开发者

android display orientation

开发者 https://www.devze.com 2023-04-11 17:14 出处:网络
I used the following piece of code in onCreate() method... But still it is displaying both messages while transists from lands开发者_开发问答cape to protrait. Please help me to getrid of it..

I used the following piece of code in onCreate() method... But still it is displaying both messages while transists from lands开发者_开发问答cape to protrait. Please help me to getrid of it..

public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.main);

     WindowManager wm=getWindowManager();
    Display dis=wm.getDefaultDisplay();

   if(dis.getWidth()>dis.getHeight())
        Toast.makeText(getBaseContext(), "Landscape", Toast.LENGTH_SHORT).show();
    else
        Toast.makeText(getBaseContext(), "Portarit", Toast.LENGTH_SHORT).show();
 }


use getResources().getConfiguration().orientation == Configuration.ORIENTATION_LANDSCAPE instead; width and height of the screen are fixed when you ask the defaultDisplay(). Otherwise you could do with getResources().getDisplayMetrics().widthPixels and getResources().getDisplayMetrics().heightPixels.

0

精彩评论

暂无评论...
验证码 换一张
取 消