简体   繁体   中英

Android, (newbie) different res imagebuttons

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM