Different design for landscape and portrait orientation android

后端 未结 4 1022
有刺的猬
有刺的猬 2020-12-03 17: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 goo

相关标签:
4条回答
  • 2020-12-03 17:50

    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

    0 讨论(0)
  • 2020-12-03 17:51

    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

    0 讨论(0)
  • 2020-12-03 17:52
    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(); 
            }
        }
    
    0 讨论(0)
  • 2020-12-03 18:06

    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 .

    0 讨论(0)
提交回复
热议问题