2012-07-04 193 views
0

我想实现的东西,在它的表面上,我认为会很容易,但研究加载和仍在挣扎。Android的布局和缩放ImageView问题

我正在设置一个ImageView,它将充当背景,图像的某些部分是按钮应位于顶部的区域。例如,背景看起来有点像这样:

Background

这使得它与所有的屏幕类型正确的纵横比这样的尺度设置为fitCenter:

Background resized

现在我试图将ImageButtons置于白色区域,如下所示:

Buttons over white areas

我想通过将每个Imagebutton对齐到背景imageView的左上角,然后设置页边距来将它放在正确的位置。这适用于某些屏幕类型,但是当背景由于设备小于背景图像而被重新调整大小时,例如我发现上面的按钮不会调整大小,因此我得到如下效果:

enter image description here

这里是布局的我想(只需一个按钮这里)类型:

<RelativeLayout android:layout_height="match_parent" android:layout_width="match_parent" xmlns:android="http://schemas.android.com/apk/res/android" android:id="@+id/outer" xmlns:tools="http://schemas.android.com/tools"> 
<ImageView android:layout_height="wrap_content" android:layout_width="wrap_content" android:id="@+id/imageView1" android:src="@drawable/no_pills_pane" android:scaleType="fitCenter" android:adjustViewBounds="true" android:layout_centerVertical="true" android:layout_centerHorizontal="true"/> 
<ImageButton android:layout_height="wrap_content" android:layout_width="wrap_content" android:id="@+id/imageButton1" android:src="@drawable/pill_pink" android:scaleType="fitXY" android:background="@null" android:layout_marginTop="50dp" android:layout_marginLeft="44dp" android:layout_alignTop="@id/imageView1" android:layout_alignLeft="@id/imageView1"/> 
</RelativeLayout> 

我敢肯定,必须有去了解这样的一个更简单的方法,任何帮助将不胜感激。

感谢 西蒙

回答

0

如果你需要的是ImageView的中居中的ImageButton,只需设置alignBottom,alignLeft,alignRight,alignTop到ImageView的

android:layout_alignBottom="@+id/imageView1" 
android:layout_alignLeft="@+id/imageView1" 
android:layout_alignRight="@+id/imageView1" 
android:layout_alignTop="@+id/imageView1" 
+0

谢谢,但我并不想居中的ImageButton ,我试图在非常特定的地方将多个图像按钮放置在背景上。我这样做是通过在imageview上左对齐,然后使用边距来放置它们。这适用于某些屏幕资源,但不是所有的按钮都不像图像视图那样缩放 –