Check orientation on Android phone

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

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

23条回答
  •  [愿得一人]
    2020-11-22 07:03

    Use this way,

        int orientation = getResources().getConfiguration().orientation;
        String Orintaion = "";
        switch (orientation)
        {
            case Configuration.ORIENTATION_UNDEFINED: Orintaion = "Undefined"; break;
            case Configuration.ORIENTATION_LANDSCAPE: Orintaion = "Landscrape"; break;
            case Configuration.ORIENTATION_PORTRAIT:  Orintaion = "Portrait"; break;
            default: Orintaion = "Square";break;
        }
    

    in the String you have the Oriantion

提交回复
热议问题