Android的 - 巴顿与缩放背景图片 [英] Android - Scaling of Button with background image
问题描述
我有一个屏幕布局,其中包括一个线性布局(水平)在3 Button控件。每个按钮有一个背景图像。请参阅下面的XML:
I have a screen layout that includes 3 Button controls contained within a linear layout (horizontal). The Buttons each have a background image. See XML below :
<LinearLayout
android:id="@+id/notificationform_llt_ApprovalBtns"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_marginTop="8dp"
android:orientation="horizontal"
android:paddingLeft="8dp"
android:paddingRight="8dp" >
<Button
android:id="@+id/notificationform_btn_Approve"
android:layout_width="0dp"
android:layout_weight="1"
android:layout_height="wrap_content"
android:background="@drawable/btn_approve"
android:onClick="btnApprove_Click" />
<Button
android:id="@+id/notificationform_btn_Reject"
android:layout_width="0dp"
android:layout_weight="1"
android:layout_height="wrap_content"
android:layout_marginLeft="10dp"
android:layout_marginRight="10dp"
android:background="@drawable/btn_reject"
android:onClick="btnReject_Click" />
<Button
android:id="@+id/notificationform_btn_Delegate"
android:layout_width="0dp"
android:layout_weight="1"
android:layout_height="wrap_content"
android:background="@drawable/btn_delegate"
android:onClick="btnDelegate_Click" />
</LinearLayout>
画面我的银河W¯¯手机(3.7)上看起来不错,但对我的Nexus上运行时7按键被拉伸水平而不是垂直方向,因此看起来被挤压。如果我的理解对不对这两种器件具有类似的决议无一不寻找图像,这是我的图像存储在哪里。我试图使图像9补丁但这并没有任何区别的绘制,华电国际的文件夹。我怎样才能使图像按比例缩放的高度和宽度是多少?
The screen looks great on my Galaxy W phone (3.7"), but when running on my Nexus 7 the buttons are stretched horizontally but not vertically and therefore look squashed. If I understand it right both these devices have similar resolution and both look for images in the drawable-hdpi folder which is where my images are stored. I've tried making the images 9-patch but this didn't make any difference. How can I make the images scale proportionally on both height and width?
推荐答案
按钮得到横向拉长,因为的LinearLayout
设置为填写父
,每个按钮
具有权重,使他们舒展。高度设置为 WRAP_CONTENT
,并没有任何内容。图像设置为背景,不会有多大按钮
是任何影响。
The buttons get stretched horizontally because the LinearLayout
is set to fill parent
, and each button
have weights that make them stretch. The heights are set to wrap_content
, and there isn't any content. The image is set as a background, which won't have any effect on how big the button
is.
这也可能是最好的更改按钮在ImageButtons并使用的android:SRC
而不是的android:背景
。例如:
It's probably best you change the Buttons to ImageButtons and use android:src
instead of android:background
. For example :
<ImageButton
android:id="@+id/notificationform_btn_Approve"
android:layout_width="0dp"
android:layout_weight="1"
android:layout_height="wrap_content"
android:src="@drawable/btn_approve"
android:onClick="btnApprove_Click" />
这篇关于Android的 - 巴顿与缩放背景图片的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!