如何设置的ImageButton来匹配屏幕不同的设备? [英] How to setup the ImageButton to match screen for different device?
问题描述
我添加的图片为 48 * 48
, 72 * 72
和 96 * 96
到 MDPI
, LDPI
和华电国际
相应。
I add the picture for 48*48
, 72*72
and 96*96
to mdpi
, ldpi
and hdpi
respective.
和添加以下code。在的AndroidManifest.xml
And add the following code in AndroidManifest.xml
<supports-screens
android:largeScreens="true"
android:normalScreens="true"
android:smallScreens="true"
android:anyDensity="true"/>
第一个问题:
First Question:
应用程序将捕捉到合适的图片本身,当我做以上操作?
The app will capture the suitable picture by itself when I do the above operation ?
第二个问题:
但如何设置在 XML按钮
文件?
如果应用程序将捕捉到合适的图片本身,所以我已经设置了宽度
和高度
到< $ C C> match_parent $像下面的code?
If app will capture the suitable picture by itself , so I have set the width
and the height
to match_parent
like the following code?
<ImageButton
android:id="@+id/imageButton1"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:src="@android:drawable/btn1" />
在此先感谢。
Thanks in advance.
-------------------------------编辑------------ ----------------
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:orientation="vertical"
android:background="#000000"
>
<RelativeLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content" >
<ImageButton
android:id="@+id/FileButton"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="10dp"
android:layout_alignParentLeft="true"
android:src="@drawable/file_viewer"/>
<ImageButton
android:id="@+id/recordButton"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
android:layout_centerInParent="true"
android:src="@drawable/record" />
<ImageButton
android:id="@+id/photo_record_mode"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginRight="10dp"
android:layout_alignParentRight="true"
android:src="@drawable/recordmode"/>
</RelativeLayout>
</LinearLayout>
我修改code象上面。
I modify the code like the above.
和我安装应用程序到设备的不同尺寸,4.7英寸和7英寸。
And I install the APP to different size of device , for 4.7 inch and 7 inch.
但它似乎使用图像的大小相同。
But it seem use the same size of picture.
和我从 Android的改变:背景
到机器人:SRC
这就像下面的图片
是否存在有什么错?
推荐答案
是的,Android将选择在运行时根据屏幕像素密度合适的图像资源。然而,你应该设置 layout_width
和 layout_height
到 WRAP_CONTENT
而不是对 match_parent
。
Yes, Android will select the right image resource at runtime depending on the screen density. However, you should set layout_width
and layout_height
to wrap_content
instead of match_parent
.
这篇关于如何设置的ImageButton来匹配屏幕不同的设备?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!