2012-03-08 27 views
0

我有一个布局问题,我想要一个图像位于两个按钮中间。所以我创建了两个按钮并定义了1的权重总和。然后将两个按钮的权重设置为.40,将图像设置为.20,以便图像在两个按钮的中间是一个小徽标。问题是图像被拉伸,按钮被推到一边。Android:错误地使用imageView重新调整尺寸按钮的布局

<Button 
    android:id="@+id/buttonClear" 
    style="@style/ButtonText" 
    android:layout_width="wrap_content" 
    android:layout_height="fill_parent" 
    android:layout_weight=".40" 
    android:background="@drawable/custombuttonred" 
    android:text="@string/clear" 
    android:textSize="50sp" /> 

<ImageView 
    android:id="@+id/myimage" 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:layout_weight=".20" 
    android:src="@drawable/imageid" /> 

<Button 
    android:id="@+id/buttonBackspace" 
    style="@style/ButtonText" 
    android:layout_width="wrap_content" 
    android:layout_height="fill_parent" 
    android:layout_weight=".40" 
    android:background="@drawable/custombuttonred" 
    android:text="@string/backspace" 
    android:textSize="20sp" /> 

+1

它是否处于线性布局?如果是的话,它的定位是什么?如果垂直,则不应使用fill_parent作为layout_height – viplezer 2012-03-08 11:12:22

+0

您是否也可以列出封闭的View? – Soham 2012-03-08 11:15:36

回答

3

我也面临着同样的问题。我使用了ImageView的按钮,并设置了背景图片。

0

我认为,如果你AR图像中的400像素宽度& 200原来的大小,你可以使用DP用于调整图像大小两个高度& width.Say px高度,只是根据屏幕大小调整大小,例如,如果你是目前正在测试的设备只能容纳图像大小的一半,那么android:layout_width =“200dp”android:layout_height =“100dp”。如果你按照调整大小使用dp图像将被调整为较小的&您正在使用的较大设备。确保当您有任何l arger设备屏幕比当前正在测试的屏幕更窄,只是尽量让图像尽可能大以获得最佳效果。