Good day, I find myself working with a toolbar which I always want to position at the bottom, I necessarily achieve the result but when I run it on different screens or emulators the design is distorted and I want the toolbar to be displayed regardless of the resolution or screen size of the device always positioned below and correctly, the design code is as follows:
<androidx.appcompat.widget.Toolbar
android:id="@+id/toolbar"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#4CAF50">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent">
<ImageButton
android:id="@+id/flecha2"
android:layout_width="35dp"
android:layout_height="30dp"
android:layout_marginTop="15dp"
android:background="@drawable/regresarflecha" />
<FrameLayout
android:layout_width="50dp"
android:layout_height="50dp"
android:layout_alignParentTop="true"
android:layout_alignParentEnd="true"
android:layout_marginEnd="25dp">
<com.airbnb.lottie.LottieAnimationView
android:id="@+id/carrito_compra"
android:layout_width="50dp"
android:layout_height="50dp"
android:layout_marginStart="10dp"
android:layout_marginTop="10dp"
android:clickable="true"
android:focusable="true"
app:lottie_autoPlay="true"
app:lottie_fileName="otrocarro.json"
app:lottie_imageAssetsFolder="assets"
app:lottie_loop="true" />
<TextView
android:id="@+id/tvCantProductos"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="right|top"
android:background="@drawable/caja_texto_circular"
android:gravity="center"
android:paddingLeft="5dp"
android:paddingTop="5dp"
android:paddingRight="5dp"
android:paddingBottom="4dp"
android:layout_marginTop="5dp"
android:text="0"
android:textColor="@android:color/white"
android:textSize="10sp"
android:textStyle="bold"
app:backgroundTint="@color/rojo"
tools:ignore="RtlHardcoded,SmallSp" />
</FrameLayout>
</RelativeLayout>
</androidx.appcompat.widget.Toolbar>
And the result should be the following:
But when running it on different devices or emulators it sends me results like the following:
This would be the complete code of the activity design
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:orientation="vertical"
android:layout_height="match_parent"
android:background="@color/white">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content" >
<EditText
android:id="@+id/etBuscador"
android:layout_width="match_parent"
android:layout_height="40dp"
android:layout_marginTop="5dp"
android:layout_marginStart="10dp"
android:layout_marginEnd="10dp"
android:background="@drawable/caja_texto_circular"
android:drawableStart="?android:attr/actionModeWebSearchDrawable"
android:iconifiedByDefault="true"
android:hint="Buscar exámen"
app:backgroundTint="#0097A7"
android:textSize="14sp"
android:padding="10dp"
tools:ignore="NewApi" />
<ImageButton
android:id="@+id/microfono"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="250dp"
android:layout_marginTop="3dp"
android:onClick="onClickImgBtnHablar"
android:src="@drawable/microphone"
app:backgroundTint="#0097A7" />
<ImageButton
android:id="@+id/btnScan"
android:layout_marginTop="3dp"
android:layout_marginStart="290dp"
android:layout_width="wrap_content"
app:backgroundTint="#0097A7"
android:src="@drawable/barcodesearch"
android:layout_height="wrap_content"/>
</RelativeLayout>
<androidx.recyclerview.widget.RecyclerView
android:id="@+id/rvLista"
android:layout_width="match_parent"
android:layout_height="610dp"
android:layout_marginTop="10dp" />
<androidx.appcompat.widget.Toolbar
android:id="@+id/toolbar"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#4CAF50">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent">
<ImageButton
android:id="@+id/flecha2"
android:layout_width="35dp"
android:layout_height="30dp"
android:layout_marginTop="15dp"
android:background="@drawable/regresarflecha" />
<FrameLayout
android:layout_width="50dp"
android:layout_height="50dp"
android:layout_alignParentTop="true"
android:layout_alignParentEnd="true"
android:layout_marginEnd="25dp">
<com.airbnb.lottie.LottieAnimationView
android:id="@+id/carrito_compra"
android:layout_width="50dp"
android:layout_height="50dp"
android:layout_marginStart="10dp"
android:layout_marginTop="10dp"
android:clickable="true"
android:focusable="true"
app:lottie_autoPlay="true"
app:lottie_fileName="otrocarro.json"
app:lottie_imageAssetsFolder="assets"
app:lottie_loop="true" />
<TextView
android:id="@+id/tvCantProductos"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="right|top"
android:background="@drawable/caja_texto_circular"
android:gravity="center"
android:paddingLeft="5dp"
android:paddingTop="5dp"
android:paddingRight="5dp"
android:paddingBottom="4dp"
android:layout_marginTop="5dp"
android:text="0"
android:textColor="@android:color/white"
android:textSize="10sp"
android:textStyle="bold"
app:backgroundTint="@color/rojo"
tools:ignore="RtlHardcoded,SmallSp" />
</FrameLayout>
</RelativeLayout>
</androidx.appcompat.widget.Toolbar>
</LinearLayout>
I hope you can help me, thank you very much in advance!
I see that you use a LinearLayout as the main container, in this case add a LinearLayout as a container for your Toolbar and define the attribute
android:layout_alignParentBottom="true"
to always alignToolbar
it to the bottom of your screen:Example:
I suggest you review about ConstraintLayout which would be the ideal currently to create your layout and through the attribute
app:layout_constraintBottom_toBottomOf="parent"
you can get your view to be placed perfectly at the bottom of your layout.