In my main activity there are several buttons that fit together on the big screen of the tablet, but not on the screen with a smaller phone. I added ScrollView so the user can scroll down to other buttons if screen size is required:
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent" android:layout_height="wrap_content" android:orientation="vertical" android:background="@drawable/bg" android:gravity="center_horizontal"> <TextView android:id="@+id/trackSelectorText" android:layout_width="wrap_content" android:layout_height="wrap_content" android:gravity="center_horizontal"/> <ScrollView android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_gravity="center"> <LinearLayout android:layout_width="match_parent" android:layout_height="wrap_content" android:orientation="vertical" android:gravity="center_horizontal"> <Button android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="foo" /> </LinearLayout> </ScrollView> </LinearLayout>
This view works, however, I have a large empty space below the last button (i.e., ScrollView may scroll too far). Both on real tablets and on an emulator with a phone configuration. If I center inner LinearLayout (instead of center_horizontal ), the space is evenly distributed between the top and bottom, which I do not want either one or the other. How to fix this layout?
I hope this image becomes clearer, imagine that ScrollView scrolls completely down and shows the last buttons. The empty space that I mean is the one below the button 6 in the right image:

source share