Supporting all screen sizes in android?

2019-03-02 17:51发布

I know this questions has been asked quite a few times. But I couldn't find the bebest possible solution to my query.

I have followed every step given in the developer support of android.
Support Multiple Screen

Putting images in different folders for different sizes. Making different layout folders for device screens. But the problem persist in the devices ranging from 4.7 inches to 5.0 inches. The layout gets quite disturbed on these devices.

What is the best and possible way to overcome that.

5条回答
劳资没心,怎么记你
2楼-- · 2019-03-02 18:31

Basically some devices belongs to large or normal group but they have so much difference in height and width for example- Nexus-4 4.7" having dimensions 768x1280 and one other device 5.1" having dimensions 480x800. So you can create layouts folders depending upon height and width. For example- layout-w480dp, layout-w720dp or layout-h800dp or layout-h1280dp. Then set views in those layouts according to your requirement.

查看更多
\"骚年 ilove
3楼-- · 2019-03-02 18:42

If you need an absolute measure of your the screen's density you can use the following code:

Got this from somewhere sometime ago, but still relevant. Enjoy it !

DisplayMetrics metrics = new DisplayMetrics(); 
try { 
WindowManager winMgr = (WindowManager)context.getSystemService(Context.WINDOW_SERVICE)        
; 
winMgr.getDefaultDisplay().getMetrics(metrics); 
} 
catch (Exception e) { 
metrics.density = 1; 
}

The value metrics.density now contains a measure of the screen's density with 160dpi density as a the 'baseline'. More info can be found here:

http://developer.android.com/reference/android/util/DisplayMetrics.html#density

查看更多
我想做一个坏孩纸
4楼-- · 2019-03-02 18:46

If you are designing any forms go for Match Parent, dont go for hardcore pixel positions. Use Relative layout.

P.S Please tell more about your compatibility issues?

查看更多
Root(大扎)
5楼-- · 2019-03-02 18:48

Please refer these link:

Multipal screen size handling!

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.

      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

The following code in the Manifest supports all dpis.

  <supports-screens android:smallScreens="true" 
      android:normalScreens="true" 
      android:largeScreens="true"
      android:xlargeScreens="true"
      android:anyDensity="true" />
查看更多
冷血范
6楼-- · 2019-03-02 18:54

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



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

    <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"
查看更多
登录 后发表回答