开发者

Detecting which layout is loaded depending on the display size?

开发者 https://www.devze.com 2023-02-20 09:52 出处:网络
I have an activity that has two layouts one in the folder layout and the other one in layout-large, (one is for the phone factor and the other one for the tablet form). How

I have an activity that has two layouts one in the folder layout and the other one in layout-large, (one is for the phone factor and the other one for the tablet form). How do I detect which layout is being loaded since in the tablet 开发者_运维知识库form I display more data?

Thanks

EDIT: I know that in the tablet it will load the layout-large but how do I know that I am running in something with a tablet form factor?


You can detect it programmatically:

(getResources().getConfiguration().screenLayout & Configuration.SCREENLAYOUT_SIZE_MASK) == Configuration.SCREENLAYOUT_SIZE_XLARGE;
getResources().getConfiguration().orientation == Configuration.ORIENTATION_LANDSCAPE;

and with other methods and properties in getResources().getConfiguration()


A simple approach would be to keep a Text view with visibility set as GONE. Keep text property for each layout different. In your code check for this view and identify which layout has been loaded.

0

精彩评论

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

关注公众号