Android的,(新手)不同的资源imagebuttons [英] Android, (newbie) different res imagebuttons

查看:143
本文介绍了Android的,(新手)不同的资源imagebuttons的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在36x36,48x48,72x72和96x96的提出了同样的图像按钮,并把他们在绘制-LDPI,绘制,MDPI,绘制,华电国际的目录。

然后,我创建了一个布局和plonked我的图像按钮那里。

(我使用Eclipse)

在你可以选择屏幕尺寸屏幕的左上角,所以我挑2.7英寸然后循环直到,直到10.1英寸......每一次我的形象按钮的大小变化。

所以我的问题是,我需要为每个屏幕尺寸不同的XML布局文件?

谢谢!

编辑XML:

 <?XML版本=1.0编码=UTF-8&GT?;
<的LinearLayout
  的xmlns:机器人=htt​​p://schemas.android.com/apk/res/android
  机器人:方向=垂直
  机器人:layout_width =FILL_PARENT
  机器人:layout_height =FILL_PARENT机器人:背景=@绘制/ background_ass>
    < TableLayout机器人:ID =@ + ID / tableLayout1机器人:layout_height =WRAP_CONTENT的android:layout_width =FILL_PARENT>
        <的TableRow机器人:ID =@ + ID / tableRow1的android:layout_width =WRAP_CONTENT机器人:layout_height =WRAP_CONTENT>
            < ImageButton的机器人:SRC =@绘制/ 1级
                机器人:ID =@ + ID / imageButton1
                安卓的onClick =button_clicked1
                机器人:背景=#00000000的android:layout_width =48dip机器人:layout_height =48dip>
            < / ImageButton的>
        < /&的TableRow GT;
        <的TableRow机器人:ID =@ + ID / tableRow2的android:layout_width =WRAP_CONTENT机器人:layout_height =WRAP_CONTENT>
            <的TextView的android:文本=TextView的机器人:ID =@ + ID / textView1
            机器人:layout_width =WRAP_CONTENT
            机器人:layout_height =WRAP_CONTENT>< / TextView的>
        < /&的TableRow GT;
        <的TableRow机器人:ID =@ + ID / tableRow3的android:layout_width =WRAP_CONTENT机器人:layout_height =WRAP_CONTENT>
        < /&的TableRow GT;
        <的TableRow机器人:ID =@ + ID / tableRow4的android:layout_width =WRAP_CONTENT机器人:layout_height =WRAP_CONTENT>< /&的TableRow GT;
    < / TableLayout>< / LinearLayout中>


解决方案

没有这些单独的文件夹的一点是,如果该文件提供了相同的名字,正确的分辨率的文件会根据屏幕尺寸选择。但要确保你的图像提供相同的名称。如果您看到按钮相应调整,那么你已经正确地做到了这一点。

I have made the same image button in 36x36,48x48,72x72 and 96x96 and put them in the drawable-ldpi,drawable-mdpi,drawable-hdpi directories.

I then created a layout and plonked my image button there.

(I am using Eclipse)

in the top left of the screen you can pick the screen size, so I picked 2.7 inches and then cycled right up till 10.1 inches...and every time my image button size changed.

So my question is, do I need to have a different xml layout file for each screen size?

Thanks!

EDIT XML:

 <?xml version="1.0" encoding="utf-8"?>
<LinearLayout
  xmlns:android="http://schemas.android.com/apk/res/android"
  android:orientation="vertical"
  android:layout_width="fill_parent"
  android:layout_height="fill_parent" android:background="@drawable/background_ass">
    <TableLayout android:id="@+id/tableLayout1" android:layout_height="wrap_content" android:layout_width="fill_parent">
        <TableRow android:id="@+id/tableRow1" android:layout_width="wrap_content" android:layout_height="wrap_content">
            <ImageButton android:src="@drawable/level1" 
                android:id="@+id/imageButton1" 
                android:onClick="button_clicked1"
                android:background="#00000000"  android:layout_width="48dip" android:layout_height="48dip">
            </ImageButton>
        </TableRow>
        <TableRow android:id="@+id/tableRow2" android:layout_width="wrap_content" android:layout_height="wrap_content">
            <TextView android:text="TextView" android:id="@+id/textView1" 
            android:layout_width="wrap_content" 
            android:layout_height="wrap_content"></TextView>
        </TableRow>
        <TableRow android:id="@+id/tableRow3" android:layout_width="wrap_content" android:layout_height="wrap_content">
        </TableRow>
        <TableRow android:id="@+id/tableRow4" android:layout_width="wrap_content" android:layout_height="wrap_content"></TableRow>
    </TableLayout>

</LinearLayout>

解决方案

No the point of those separate folders is that, if you provide the same name for that file, the correct resolution file will be chosen based on the screen size. But make sure that you provide the same name for the image. If you see the button resizing accordingly, then you have done this correctly.

这篇关于Android的,(新手)不同的资源imagebuttons的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆