简体   繁体   中英

Supporting Multiple Screens (phone and tablet)

I am beginner to programming for android. First of all i need that my app will be supported by 2 devices phone (480x800) and tablet (1280x800).

I read this and tried to do step by step. Supporting Multiple Screens

So i created folders with layouts:

res/layout/firstPage.xml//this is by default phone layout port and land
res/layout-sw720dp/firstPage.xml//this is tablet port layout
res/layout-sw720dp-land/firstPage.xml//this is tablet land layout

My xml looks like this:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_gravity="center_vertical"
    android:baselineAligned="false"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:orientation="vertical" >

    <Button
        android:id="@+id/button1"
        android:text="@string/button1" />

    <Button
        android:id="@+id/button2"
        android:text="@string/button2" />

    <Button
        android:id="@+id/button3"
        android:text="@string/button3" />

</LinearLayout>

I don't give more info about button because in every layout they are different.

In my AndroidManifest.xml i have this line:

<supports-screens android:anyDensity="true" android:normalScreens="true" android:resizeable="true" android:smallScreens="true" android:largeScreens="true"/>

Maybe i don't need to set true for others if i set tru to this anyDensity="true"

So i think i did everything as i should. But when i wanted to test on tablet it shows me layout by default of phone. So what i missed ? Or i need to do some coding also ?

Edited:

I think i understand why... Beginning with Android 3.2 (API level 13), the above size groups are deprecated and you should instead use the swdp configuration qualifier to define the smallest available width required by your layout resources.

My table is 3.1 so that why it didn't find layout ? But what to do if i want to support from 2.1 to 4 ?

Sollution:

You Should have to follow: Best Practise

Try to use the different layout for different screen size:

As like:

res/layout/my_layout.xml         // layout for normal screen size ("default")res/layout-small/my_layout.xml       // layout for small screen size
res/layout-large/my_layout.xml       // layout for large screen size
res/layout-xlarge/my_layout.xml      // layout for extra large screen size
res/layout-xlarge-land/my_layout.xml // layout for extra large in landscape orientation

Use Different size of images as per the different Screen Size of device:

As Like:

res/drawable-mdpi/my_icon.png        // bitmap for medium density
res/drawable-hdpi/my_icon.png        // bitmap for high density
res/drawable-xhdpi/my_icon.png       // bitmap for extra high density

Still if its not solve your problem then use the static size for the images for respective different layout.

As per my point of view and the Document it self explain that you should have to follow certain steps to do this.

Hope it will helps you. nd if not then let me know where you getting stop in managing layout.

Thanks.

the layout-sw720p only works in 3.2 and after android versions and not on 3.0 and 3.1

Hope this helps here is the link http://developer.android.com/guide/practices/screens_support.html Under Using new size qualifiers --> Table 2. New configuration qualifers for screen size (introduced in Android 3.2).

try using this...

res/layout/firstPage.xml//this is by default phone layout port and land
res/layout-xlarge/firstPage.xml//this is tablet port layout
res/layout-xlarge-land/firstPage.xml//this is tablet land layout

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