How can I get one column in portrait mode and two columns in landscape mode with a ListView
or TableLayout
.
For example, in Portrait:
And in Landscape :
I thought to use ListView
with one column in portrait mode and TableLayout
with two columns in landscape mode, but before that, I want to know your suggestions.
I recommend using a ListView rather than a TableLayout, since ListViews only create enough Views to fill the screen while a TableLayout will create every resource whether they are visible or not. In this way a TableLayout is slower and might even crash your app.
You can check the device's orientation with one of the answers from: Check orientation on Android phone . Then if the orientation is:
Loading different layouts in a ListView requires a simple custom Adapter. If you haven't written one before, here is a tutorial to help you.
It'd be way easy for you to use a GridView. You can set/choose number of columns on runtime and hence set them differently in portait vs landscape mode. That way, you'd just be manipulating a single view.
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.