Hello! I created a menu and I'm interested in how to reduce the image from below and above, because there is a lot of empty space. Pictures 72x72, are stored in Drawable, refused folders with different resolutions, so as not to take up much space + in landscape orientation, this is another layout, they scale normally. android: scaleType rebuilt everything. Here is the code:

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:orientation="vertical" android:layout_width="fill_parent" android:layout_height="wrap_content"> <include layout="@layout/title"/> <LinearLayout android:orientation="horizontal" android:layout_width="fill_parent" android:layout_height="wrap_content" android:background="@drawable/bg_button"> <RelativeLayout android:layout_width="0dp" android:layout_height="fill_parent" android:layout_weight="0.2"> <RelativeLayout android:id="@+id/homeButtonLayout" android:orientation="vertical" android:layout_gravity="top" android:layout_width="wrap_content" android:layout_height="wrap_content"> <ImageView android:id="@+id/homeButton" android:layout_width="fill_parent" android:layout_height="wrap_content" android:scaleType="centerInside" android:src="@drawable/ic_home_g"/> </RelativeLayout> <LinearLayout android:id="@+id/homeButtonText" android:layout_below="@id/homeButtonLayout" android:orientation="vertical" android:layout_width="fill_parent" android:layout_height="wrap_content"> <TextView android:layout_width="wrap_content" android:layout_gravity="center" android:layout_height="wrap_content" style="@style/buttonFont" android:text="@string/str_base_activity_toolbar_home"/> </LinearLayout> </RelativeLayout> <RelativeLayout android:layout_width="0dp" android:layout_height="fill_parent" android:layout_weight="0.2"> <RelativeLayout android:id="@+id/homeButtonLayout" android:orientation="vertical" android:layout_gravity="top" android:layout_width="wrap_content" android:layout_height="wrap_content"> <ImageView android:id="@+id/homeButton" android:layout_width="fill_parent" android:layout_height="wrap_content" android:scaleType="centerInside" android:src="@drawable/ic_home_g"/> </RelativeLayout> <LinearLayout android:id="@+id/homeButtonText" android:layout_below="@id/homeButtonLayout" android:orientation="vertical" android:layout_width="fill_parent" android:layout_height="wrap_content"> <TextView android:layout_width="wrap_content" android:layout_gravity="center" android:layout_height="wrap_content" style="@style/buttonFont" android:text="@string/str_base_activity_toolbar_home"/> </LinearLayout> </RelativeLayout> <RelativeLayout android:layout_width="0dp" android:layout_height="fill_parent" android:layout_weight="0.2"> <RelativeLayout android:id="@+id/availableButtonLayout" android:orientation="vertical" android:layout_width="wrap_content" android:layout_height="wrap_content"> <ImageView android:id="@+id/availableButton" android:layout_width="fill_parent" android:layout_height="wrap_content" android:scaleType="centerInside" android:src="@drawable/ic_available_g"/> <TextView android:id="@+id/availableButtonCounter" android:layout_alignTop="@id/availableButton" android:layout_alignRight="@id/availableButton" android:text="2234" android:visibility="gone" style="@style/buttonBadge"/> </RelativeLayout> <LinearLayout android:id="@+id/availableButtonText" android:layout_below="@id/availableButtonLayout" android:orientation="vertical" android:layout_width="fill_parent" android:layout_height="wrap_content"> <TextView android:layout_width="wrap_content" android:layout_gravity="center" android:layout_height="wrap_content" style="@style/buttonFont" android:text="@string/str_base_activity_toolbar_available"/> </LinearLayout> </RelativeLayout> <RelativeLayout android:layout_width="0dp" android:layout_height="fill_parent" android:layout_weight="0.2"> <RelativeLayout android:id="@+id/homeButtonLayout" android:orientation="vertical" android:layout_gravity="top" android:layout_width="wrap_content" android:layout_height="wrap_content"> <ImageView android:id="@+id/homeButton" android:layout_width="fill_parent" android:layout_height="wrap_content" android:scaleType="centerInside" android:src="@drawable/ic_home_g"/> </RelativeLayout> <LinearLayout android:id="@+id/homeButtonText" android:layout_below="@id/homeButtonLayout" android:orientation="vertical" android:layout_width="fill_parent" android:layout_height="wrap_content"> <TextView android:layout_width="wrap_content" android:layout_gravity="center" android:layout_height="wrap_content" style="@style/buttonFont" android:text="@string/str_base_activity_toolbar_home"/> </LinearLayout> </RelativeLayout> <RelativeLayout android:layout_width="0dp" android:layout_height="fill_parent" android:layout_weight="0.2"> <RelativeLayout android:id="@+id/homeButtonLayout" android:orientation="vertical" android:layout_gravity="top" android:layout_width="wrap_content" android:layout_height="wrap_content"> <ImageView android:id="@+id/homeButton" android:layout_width="fill_parent" android:layout_height="wrap_content" android:scaleType="centerInside" android:src="@drawable/ic_home_g"/> </RelativeLayout> <LinearLayout android:id="@+id/homeButtonText" android:layout_below="@id/homeButtonLayout" android:orientation="vertical" android:layout_width="fill_parent" android:layout_height="wrap_content"> <TextView android:layout_width="wrap_content" android:layout_gravity="center" android:layout_height="wrap_content" style="@style/buttonFont" android:text="@string/str_base_activity_toolbar_home"/> </LinearLayout> </RelativeLayout> </LinearLayout> <LinearLayout android:id="@+id/parentLinearLayout" android:orientation="vertical" android:layout_width="fill_parent" android:layout_height="fill_parent" android:background="@drawable/bg_main"> </LinearLayout> </LinearLayout> 

Here's how it turns out:

alt text

    1 answer 1

    1. You can use the weight (android: layout_weight attribute), or rather the ratio. For example, 1 to 3. That is, one view is given a weight equal to 1, another 3. Or you can even use fractional values, then the place will be compressed. In general, using weight is one of the most flexible ways to position components. Not counting the new layouts. But then you have to rewrite your entire layout, since the weight is used only in LinearLayout.
    2. You can play with the ImageView attribute scaleType or adjustViewBounds = "true". Put fitXY in scaleType, but then the pictures may be flattened.

    Try it. There are many options.

    • Thank! adjustViewBounds = "true" slightly reduced the overall height. scaleType I was trying everything, nothing was good and fitXY was trying too. Changing everything to LinearLayout is not an option. Can something else somehow reduce the overall height? - zesen
    • one
      Honestly, I can’t see what is what in your code, but you can try to reduce the weight from 0.2 to 0.15 where you have this strip of pictures. But in general, somehow everything is confusing. Rewrite to a simpler scheme - it will be easier for you to accompany, and the future reader of the code. - DroidAlex
    • Thank you very much, the change in weight did not help, I will leave it as it is for now ... - zesen