mind
mind

Reputation: 432

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

Upvotes: 0

Views: 1105

Answers (3)

Pratik Dasa
Pratik Dasa

Reputation: 7439

Use equal weight attribute in our ImageButtons. It will occupy the space as compare to Screen Sizes, and use dp not dip.

Upvotes: 0

nurisezgin
nurisezgin

Reputation: 1570

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>

Upvotes: 1

Tim Kranen
Tim Kranen

Reputation: 4222

Set your layout_width attribute to "fill_parent" and make sure that the scaleType is fitXY

Upvotes: 0

Related Questions