How to support different screen size in android

前端 未结 9 893
天涯浪人
天涯浪人 2020-11-22 05:29

I\'m developing an app in android and I have to support all different screen sizes and density. So i\'ve created different folder for layout : layout-small layout-larg

9条回答
  •  无人共我
    2020-11-22 06:08

    It sounds lofty,when it comes to supporting multiple screen Sizes.The following gves better results .

    res/layout/layout-w120dp
    res/layout/layout-w160dp
    res/layout/layout-w240dp
    res/layout/layout-w160dp
    res/layout/layout-w320dp
    res/layout/layout-w480dp
    res/layout/layout-w600dp
    res/layout/layout-w720dp
    

    Chek the Device Width and Height using Display Metrics

    Place/figure out which layout suits for the resulted width of the Device .

    let smallestScreenWidthDp="assume some value(Which will be derived from Display metrics)"
    

    All should be checked before setContentView().Otherwise you put yourself in trouble

         Configuration config = getResources().getConfiguration();
    
         Configuration config = getResources().getConfiguration();
    
            if (config.smallestScreenWidthDp >= 600) {
                setContentView(R.layout.layout-w600dp);
            } else {
                setContentView(R.layout.main_activity);
            }
    

    In the top,i have created so many layouts to fit multiple screens,it is all depends on you ,you may or not.You can see the play store reviews from Which API ,The Downloads are High..form that you have to proceed.

    I hope it helps you lot.Few were using some third party libraries,It may be reduce your work ,but that is not best practice. Get Used to Android Best Practices.

    Check This Out

提交回复
热议问题