Different design for landscape and portrait orientation android

后端 未结 4 1032
有刺的猬
有刺的猬 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: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(); 
            }
        }
    

提交回复
热议问题