My project doesnt support multiple devices screen view

一曲冷凌霜 提交于 2019-12-02 11:11:07

In android, to support as much devices as possible, you can supply multiple definitions of one layout. First you need to add those folders into your resources, and for each one you can specify different xml files of the same layout to meet the device screens you want your app to be used on.

Here is an example on how the folder structure might look 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

res/layout/main_activity.xml           // For handsets (smaller than 600dp available width)
res/layout-sw600dp/main_activity.xml   // For 7” tablets (600dp wide and bigger)
res/layout-sw720dp/main_activity.xml   // For 10” tablets (720dp wide and bigger)

(in app manifest)

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

For more info on supporting multiple screens i strongly recommend reading the google docs about it. Here is a link to the documents. http://developer.android.com/guide/practices/screens_support.html

Declare your dimensions values-small,values-large,values-xlarge etc.

Don't forget to declare support-screens in your AndroidManifest.xml

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

Reffer to http://developer.android.com/guide/practices/screens_support.html for more info.

You can proceed as following

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

res/layout/main_activity.xml           # For handsets (smaller than 600dp available width)
res/layout-sw600dp/main_activity.xml   # For 7” tablets (600dp wide and bigger)
res/layout-sw720dp/main_activity.xml   # For 10” tablets (720dp wide and bigger)

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


<supports-screens 
        android:smallScreens="true" 
        android:normalScreens="true" 
        android:largeScreens="true"
        android:xlargeScreens="true"  
        android:anyDensity="true"/>
Gopal Singh

In android you have to set images in different different drawable as per screen size and make layout as per screen size also.

res/layout/my_layout.xml(drawable also like layout) ---- default layout. 
res/layout-layout-hdpi/my_layout.xml ---- layout for hdpi screen size 
res/layout-layout-large-hdpi/my_layout.xml ---- layout for large hdpi screen size 
res/layout-layout-mdpi/my_layout.xml ---- layout for mdpi screen size(normal tables also) 
res/layout-layout-Xdpi/my_layout.xml ---- layout for Xhdpi screen Size(high resolution)
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!