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

前端 未结 8 1975
孤街浪徒
孤街浪徒 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:38

    You can set a different android:tag attribute on the views in each different resource file, and read the tag back at runtime with View.getTag().

    Example:

    layout-xlarge-land/my_act.xml

    
    

    layout-xlarge/my_act.xml

    
    

    MyActivity.java

    String tag = view.getTag();
    if (tag.equals("xlarge-landscape") {
        ...
    }
    

提交回复
热议问题