【问题标题】:ANDROID: How to fix the position of a ImageButton relative to the background?ANDROID:如何固定 ImageButton 相对于背景的位置?
【发布时间】:2010-11-16 17:41:52
【问题描述】:

如何固定 ImageButton/Button/ImageView 相对于背景的位置/布局?

我尝试过这样的事情:

<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 不会散开,也不会按比例尊重底部边距。

【问题讨论】:

  • 抱歉,不清楚您要完成什么。你给 ImageButton 一个明确的宽度和高度,所以它永远不会拉伸。你希望它根据它的父母有多大来伸展?

标签: android layout background imagebutton android-relativelayout


【解决方案1】:

这是因为您对高度和 with 进行了硬编码。将它们设置为 fill_parent ,然后它将适合边距。

【讨论】:

  • fill_parent 将适合边距,但如何固定相对于背景的大小/位置?例如:x % background_width(不是 52dip)、y % background_height(不是 52dip)和 z % background_bottom(不是 87dip)?
  • 如果我理解正确,我认为最好的选择是使用LinearLayout 并将高度或宽度设置为 0dip,然后将权重设置为所需的百分比。
猜你喜欢
  • 2018-11-28
  • 1970-01-01
  • 1970-01-01
  • 2012-12-25
  • 1970-01-01
  • 2013-04-07
  • 2014-03-30
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多