Check orientation on Android phone

前端 未结 23 1960
庸人自扰
庸人自扰 2020-11-22 06:26

How can I check if the Android phone is in Landscape or Portrait?

23条回答
  •  爱一瞬间的悲伤
    2020-11-22 07:14

    There is one more way of doing it:

    public int getOrientation()
    {
        if(getResources().getDisplayMetrics().widthPixels>getResources().getDisplayMetrics().heightPixels)
        { 
            Toast t = Toast.makeText(this,"LANDSCAPE",Toast.LENGTH_SHORT);
            t.show();
            return 1;
        }
        else
        {
            Toast t = Toast.makeText(this,"PORTRAIT",Toast.LENGTH_SHORT);
            t.show();
            return 2;
        }       
    }
    

提交回复
热议问题