• After 15+ years, we've made a big change: Android Forums is now Early Bird Club. Learn more here.

Apps How to assign a flexible size to the image button?

I want to create image buttons with a flexible size so that they can fit in any android device without problems as when creating them the regular way I don't get the required result,

for example:

aaa.png


And on another device:


45689a2kh
bbb.png


Here's the code I'm using:

[HIGH]
<GridLayout
android:id="@+id/grid1"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_centerInParent="true"
android:layout_marginTop="150dp"
android:background="@drawable/corneres"
android:columnCount="1"
android:eek:rientation="vertical" >

<ImageButton
android:id="@+id/imageButton1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="@drawable/homeview"
android:scaleType="centerInside"
android:adjustViewBounds="true" />

<ImageButton
android:id="@+id/imageButton3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_column="0"
android:layout_gravity="right|top"
android:layout_row="0"
android:src="@drawable/profiles"
android:scaleType="centerInside"
android:adjustViewBounds="true"/>

<ImageButton
android:id="@+id/imageButton2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_column="0"
android:layout_gravity="center"
android:layout_row="0"
android:src="@drawable/ac"
android:scaleType="centerInside"
android:adjustViewBounds="true"/>
.
.
. // another three buttons
</GridLayout>
[/HIGH]
 

BEST TECH IN 2023

We've been tracking upcoming products and ranking the best tech since 2007. Thanks for trusting our opinion: we get rewarded through affiliate links that earn us a commission and we invite you to learn more about us.

Smartphones