Alan
Alan

Reputation: 11

ANDROID: How to fix the position of a ImageButton relative to the background?

How to fix the position/layout of a ImageButton/Button/ImageView relative to the background?

I'd tried something like this:

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:background="@drawable/background_img"
>

<ImageButton
    android:id="@+id/btn1"
    android:layout_width="52dip"
    android:layout_height="52dip"
    android:layout_alignParentBottom="true"
    android:layout_centerHorizontal="true"
    android:layout_marginBottom="87dip"        
    android:background="@drawable/btn1"
/>    
</RelativeLayout> 

When I change the display resolution, the background_img stretch to cover the new area, but the ImageButton doesn't streetch and doesn't respect the bottom margin proportionately.

Upvotes: 1

Views: 3671

Answers (1)

Nathan Schwermann
Nathan Schwermann

Reputation: 31503

It's because you hardcoded the height and with. Set them to fill_parent and it will then fit the margin.

Upvotes: 1

Related Questions