Creating multi-screen support app android

六眼飞鱼酱① 提交于 2019-11-27 08:57:26
Arun Antoney

Try out like:

  • layout-sw320dp
  • layout-sw480dp
  • layout-sw600dp
  • layout-sw720dp

instead of

  • layout-small,
  • layout-large etc...

Please refer below link:

http://developer.android.com/guide/practices/screens_support.html For Different screen size, The following is a list of resource directories in an application that provides different layout designs for different screen sizes and different bitmap drawables for small, medium, high, and extra high density screens. you could use different size of the layout files in res folder and also vary for drawable images based on the density..

  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/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

<compatible-screens>
    <screen
        android:screenDensity="ldpi"
        android:screenSize="small" />
    <screen
        android:screenDensity="mdpi"
        android:screenSize="normal" />
    <screen
        android:screenDensity="xhdpi"
        android:screenSize="large" />
    <screen
        android:screenDensity="xhdpi"
        android:screenSize="xlarge" />        
</compatible-screens>

And followed by any activity use this lines..

android:configChanges="orientation|screenSize|keyboardHidden"

In values folder naming convention like layout-small only works for devices with api version less than 3.1. You should create values file with naming like layout-sw600dp for api level greater than 3.1. read this http://developer.android.com/guide/practices/screens_support.html3.1api

like this you should create layout-sw600dp, layout-sw720dp for each type of devices. layout-sw600dp means this layout works for devices with smallest width of 600dp If you have layout-600dp and layout-sw720dp folders. first layout folder works for devices with smallest width of 600dp(7 inch tablet) to 720dp and second works for devices with smallest width above 720dp(10 inch tablet).

If your minimum required version is above 3.1 you don't need have layout-small, layoutxLarge folders. otherwise you have to consider both type of layout fromats.

Here is a quick checklist about how you can ensure that your application displays properly on different screens:

Use wrap_content, fill_parent, or dp units when specifying dimensions in an XML layout file. Do not use hard coded pixel values in your application code(.java files). Do not use AbsoluteLayout (it's deprecated in Android 1.5). You should instead use RelativeLayout, which uses relative positioning to lay out its child views. Supply alternative bitmap drawables for different screen densities.

Take time and read these screens_support or to get a better idea see How Android Finds the Best-matching Resource so that you know where to place your resources.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!