I have the following XML layout code in an Android app that I’ve been tinkering with:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 |
<?xml version="1.0" encoding="utf-8"?> <layout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.com/tools"> <data> <variable name="viewModel" type="net.catzie.sampleapp.MainViewModel" /> </data> <ScrollView android:layout_width="match_parent" android:layout_height="match_parent"> <GridLayout android:layout_width="match_parent" android:layout_height="match_parent" android:background="#aaa" android:columnCount="4" android:rowCount="5"> ... </GridLayout> </ScrollView> </layout> |
I wrapped my GridLayout
in a ScrollView
because on the landscape orientation of the Android app’s screen, my grid contents are cut from the view because they’re too tall, and there’s no way to see them without a scrollbar, which the ScrollView
provides.
That gave birth to another problem though. The landscape view looks fine, but the vertical view became too short!
After a few clicks at Google search results I found something that helped:
1 |
android:fillViewport="true" |
I added the above attribute to my ScrollView, and voila! A GridLayout that scrolls vertically on landscape view, and fits the height of the Android device screen perfectly on portrait view~