Different design for landscape and portrait orientation android

£可爱£侵袭症+ 提交于 2019-11-26 16:59:42

问题


Can we have a different xml for landscape and different xml for portrait orientation?

I am working on a simple app, have few buttons and textviews, the xml looks good in portrait, But with same xml when I check the landscape orientation, design doesn't look good.

Any suggestions are appreciated.. Thank you.


回答1:


Yes ofcourse.

You will have to create two versions of xml files and put in layout-port and layout-land folder inside res folder.

eg :

res/layout [Portrait Mode; default]
 main.xml
res/layout-land [Landscape Mode]
 main.xml 

You can refer further more on the same at http://developer.android.com/training/basics/supporting-devices/screens.html




回答2:


If you want to make another layout for landscape then put it in

res -> layout-land folder .

Both the names of the xml are must be same for which is used for portrait and landscape .




回答3:


public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_screen_orientation_app);
   if(getResources().getDisplayMetrics().widthPixels>getResources().getDisplayMetrics().
            heightPixels) 
        {  
            Toast.makeText(this,"Screen switched to Landscape mode",Toast.LENGTH_SHORT).show(); 
        } 
        else 
        { 
            Toast.makeText(this,"Screen switched to Portrait mode",Toast.LENGTH_SHORT).show(); 
        }
    }



回答4:


you should make a different xml file for landscape orientation. below link can help you

http://developer.android.com/training/basics/supporting-devices/screens.html



来源:https://stackoverflow.com/questions/12781449/different-design-for-landscape-and-portrait-orientation-android

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