Search code examples
androidxmllayoutscaleimagebutton

Fitting imageButtons into different screen sizes


i am new to android programming. I have a problem scaling ImageButtons to different screen-resolutions. I made different image sizes based on the dpi and put them into hdpi(120px*72px,160dpi), mdpi(80px*48px,160dpi) and xhdpi(160px*96px,160dpi) But on screen-resolutions like 1280x720 there is a little bit of space on the right side. I tried things like:

android:scaleType="fitXY"
android:scaleType="centerInside"
android:adjustViewBounds="true"

but nothing worked. Also, i am not quite sure what these do. Like i said, i am new to android.

https://www.dropbox.com/sh/dmtcn4lxyxxh5wt/vpq9pBMOSl

<ImageButton
    android:id="@+id/imageButtonsearch"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_alignParentBottom="true"
    android:layout_toRightOf="@+id/imageButtonshare"
    android:background="@null"
    android:scaleType="centerInside"
    android:src="@drawable/selector_search"
    android:adjustViewBounds="true" />

Thanks in advance


Solution

  • You should use linearlayout and than set all imagebutton's layout_weight attr to 0.25 Linearlayout must be in the parent bottom.

    Like this;

    <LinearLayout 
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_alignParentBottom="true"
        android:orientation="horizontal">
    
        <ImageButton 
            android:layout_width="0dip"
            android:layout_height="wrap_content"
            android:layout_weight="0.25"
            android:src="@drawable/ic_launcher"/>
    
        <ImageButton 
            android:layout_width="0dip"
            android:layout_height="wrap_content"
            android:layout_weight="0.25"
            android:src="@drawable/ic_launcher"/>
    
        <ImageButton 
            android:layout_width="0dip"
            android:layout_height="wrap_content"
            android:layout_weight="0.25"
            android:src="@drawable/ic_launcher"/>
    
        <ImageButton 
            android:layout_width="0dip"
            android:layout_height="wrap_content"
            android:layout_weight="0.25"
            android:src="@drawable/ic_launcher"/>
    
    </LinearLayout>