Search code examples
androidtextviewandroid-imageviewandroid-constraintlayout

Display elements in the same place for all devices


I'm trying move items bottom middle, and I want that it was on bottom middle for all devices. And I need add text above and under my imagviews on middel. Sorry for trivial question.

This is my code in Android Studio.

 <?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:gravity="center"
    android:orientation="horizontal"
    android:padding="16dp">
    
    <ImageView
        android:id="@+id/img_instagram"
        android:layout_width="48dp"
        android:layout_height="48dp"
        android:layout_centerInParent="true"
        android:src="@drawable/ic_instagram" />

    <ImageView
        android:id="@+id/img_vk"
        android:layout_width="48dp"
        android:layout_height="48dp"
        android:layout_centerInParent="true"
        android:layout_marginStart="8dp"
        android:src="@drawable/ic_vk_crug" />

    <ImageView
        android:id="@+id/gmail"
        android:layout_width="48dp"
        android:layout_height="48dp"
        android:layout_centerInParent="true"
        android:layout_marginStart="8dp"
        android:src="@drawable/ic_icons8_gmail" />

</LinearLayout>

Solution

  • try to set two gravitys with

    android:gravity="center_horizontal|bottom"
    

    btw. layout_centerInParent is RelativeLayout params, is no-op in your code, you may safely remove all occurences

    Adding a text is more complex, as you are using LinearLayout as root. You should switch to RelativeLayout or ConstraintLayout