简体   繁体   中英

android multiple layouts for different screen sizes

I have a screen that I need to remove some items on smaller screens because they will not fit. I search for items in the layout to populate with live data in code, such as populating names etc. There are 5 items that need to be populated in my large layout but only 2 in my small layout as three I removed because they won't fit. How in my Activity can I tell that I am in "Small mode" and not search the layout for the three id's that I want to skip and not populate?

Do I need to just search for them and catch the errors and ignore or is there a better way?

Thanks

It looks like in this circumstance the widgets will return null when I attempt to find them if the layout chosen doesn't support that widget. So I can just detect if its null and if so skip populating the widget.

You will want to utilize a combo of the resource directories (high, medium, low) and follow the guidelines on how to support multiple screen sizes from the android documentation. Also you can get the screen dimensions if you need to anything specific in the code. See these links.

Get screen dimensions in pixels http://developer.android.com/guide/practices/screens_support.html

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM