2010-11-16 82 views
1

如何修复ImageButton/Button/ImageView相对于背景的位置/布局?ANDROID:如何修复ImageButton相对于背景的位置?

我试过这样的事情:

<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> 

当我改变显示器的分辨率,background_img拉伸以覆盖新的领域,但ImageButton的不streetch,不尊重底边距比例。

+0

对不起,它不清楚你想完成什么。你给ImageButton一个明确的宽度和高度,所以它永远不会伸展。你想让它根据父母有多大来展开? – 2010-11-16 17:47:39

回答

1

这是因为你硬编码的高度和。将它们设置为fill_parent,然后它将适合边距。

+0

fill_parent将适合边距,但如何修复相对于背景的大小/位置?例如:x%background_width(不是52dip),y%background_height(不是52dip)和z%background_bottom(不是87dip)? – Alan 2010-11-16 18:59:31

+0

如果我理解正确,我认为最好的选择是使用LinearLayout,并将高度或宽度设置为0dip,然后将权重设置为您想要的百分比。 – schwiz 2010-11-16 20:28:32