You need to make markup on the main screen of the application in the form of 6 icons.
There will be 2 rows of 3 icons, and under each of them is an inscription.
I made 2 LinearLayout and centered them, but I just can not make labels so that they look exactly in the center of the icons on the screen of all Android devices.

Tell me, how can I do better?

Markup :

 <LinearLayout android:orientation="horizontal" android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_below="@+id/imageView2" android:layout_alignRight="@+id/imageView2" android:layout_alignEnd="@+id/imageView2" android:layout_marginTop="35dp" android:id="@+id/linearLayout" android:gravity="center_horizontal"> <ImageButton android:layout_width="50dp" android:layout_height="50dp" android:id="@+id/imageButton4" android:layout_alignParentBottom="true" android:layout_alignParentLeft="true" android:layout_alignParentStart="true" android:onClick="gotoNewActivityStart" android:background="@drawable/ico1" android:layout_marginRight="30dp" /> <ImageButton android:layout_width="50dp" android:layout_height="50dp" android:id="@+id/imageButton5" android:background="@drawable/ico2" android:onClick="gotoNewActivityLex" android:layout_marginRight="30dp" /> <ImageButton android:layout_width="50dp" android:layout_height="50dp" android:id="@+id/imageButton6" android:background="@drawable/map" android:onClick="gotoNewActivityMap" /> </LinearLayout> 
  • @pavlofff, but how can I better act so that everything is done beautifully? - Dmitry
  • Use TableLayout with 3x4 cells - TableLayout position the pictures and text in rows, center inside the cell with gravity - pavlofff
  • If you are given an exhaustive answer, mark it as correct (a daw opposite the selected answer). - Nicolas Chabanovsky

3 answers 3

Everything is simple - you need to put the ImageButton and TextView just into one vertical LinearLayout and that's it. And I also noticed that since you set the android:background property, there is no point in using the ImageButton , so I just replaced them with a Button . ImageButton used with the android:src="@drawable/ic_launcher" attribute android:src="@drawable/ic_launcher"

  <LinearLayout android:layout_width="match_parent" android:layout_height="match_parent" android:orientation="horizontal" > <LinearLayout android:layout_width="50dp" android:layout_height="wrap_content" android:layout_marginRight="30dp" android:orientation="vertical" > <Button android:id="@+id/imageButton4" android:layout_width="match_parent" android:layout_height="50dp" android:background="@drawable/ic_launcher" android:onClick="gotoNewActivityStart" /> <TextView android:layout_width="match_parent" android:layout_height="wrap_content" android:gravity="center" android:text="@android:string/ok" /> </LinearLayout> <LinearLayout android:layout_width="50dp" android:layout_height="wrap_content" android:layout_marginRight="30dp" android:orientation="vertical" > <Button android:id="@+id/imageButton5" android:layout_width="match_parent" android:layout_height="50dp" android:background="@drawable/ic_launcher" android:onClick="gotoNewActivityLex" /> <TextView android:layout_width="match_parent" android:layout_height="wrap_content" android:gravity="center" android:text="@android:string/ok" /> </LinearLayout> <LinearLayout android:layout_width="50dp" android:layout_height="wrap_content" android:orientation="vertical" > <Button android:id="@+id/imageButton6" android:layout_width="match_parent" android:layout_height="50dp" android:background="@drawable/ic_launcher" android:onClick="gotoNewActivityMap" /> <TextView android:layout_width="match_parent" android:layout_height="wrap_content" android:gravity="center" android:text="@android:string/ok" /> </LinearLayout> </LinearLayout> 
  • @Evgeny_Karavashkin, you really helped! Thank! - Dmitry

So you have 2 rows of 3 icons.

I would make one LinearLayout, horizontal, into which weight to break into 3 parts.

In each part of the LinearLayout is vertical, with gravity = center_horizontal, and in which there is a picture, caption, picture, caption.

    As an option to place in LinearLayout not three ImageButton , but three centered LinearLayout with a picture and caption