How can I detect which layout is selected by Android in my application?

前端 未结 8 1974
孤街浪徒
孤街浪徒 2020-12-12 10:35

Assume I have an activity with three different layouts in different resource folders. For example:

layout-land/my_act.xml
lay

8条回答
  •  野趣味
    野趣味 (楼主)
    2020-12-12 11:35

    You can get info about screen orientation and size from Resources object. From there you can understand which layout is used.

    getResources().getConfiguration().orientation; - returns either Configuration.ORIENTATION_PORTRAIT or Configuration.ORIENTATION_LANDSCAPE.

    int size = getResources().getConfiguration().screenLayout; - returns mask of screen size. You can test against Small, Normal, Large, xLarge sizes. For example:

    if ((size & Configuration.SCREENLAYOUT_SIZE_XLARGE)==Configuration.SCREENLAYOUT_SIZE_XLARGE)
    

提交回复
热议问题