Keep ScrollView Too High

I try to prevent ScrollView from taking up too much space at the bottom of the screen, as it keeps my two buttons from showing. I also do not want to manually set the height for ScrollView.

<LinearLayout android:layout_width="fill_parent" android:layout_height="fill_parent" android:orientation="vertical"> <LinearLayout ... android:orientation="horizontal"> <Button .../> <TextView .../> <Button .../> </LinearLayout> <ScrollView android:layout_width="math_parent" android:layout_height="wrap_content"> <ImageView .../> <ImageView .../> <ImageView .../> </ScrollView> <LinearLayout ... android:orientation="horizontal"> <Button .../> <Button .../> </LinearLayout> </LinearLayout> 

This is a generalized version of my layout. What happens is that the ScrollView extends all the way to the bottom of the screen no matter how many elements are in it. This will cause the two buttons at the bottom of the screen to not be visible.

How can I stop this if I don’t manually set the height for ScrollView?

I used android:layout_height="wrap_content" for all of my views.

Shouldn't it automatically distribute the height of the views according to the height of the screen?

(It is required to include images, but my reputation is still not high enough (-_-))

+4
source share
2 answers

The way I decided today is to use RelativeLayout as a base. Attach two LinearLayout to the top and bottom of RelLayout respectively. Then I would insert ScrollView , but I would not set its layout properties as follows:

android:layout_below="topLinearLayout" android:layout_above="bottomLinearLayout"

+2
source

Have you tried using layout_weight for ScrollView . IIRC, if a non-zero weight is set for the ONE element (and the corresponding size is 0dp), then it will fill the remaining space in this dimension after you select the dimensions for the sister's visions (in this case LinearLayout above and below the ScrollView .

Sorry, I do not have a check for Android, and it has been a while.

 <LinearLayout android:layout_width="match_parent" android:layout_height="match_parent" android:orientation="vertical"> <LinearLayout> ... Something at the top ... </LinearLayout> <ScrollView android:layout_width="match_parent" **android:layout_height="0dp" android:layout_weight="1"**> <ImageView .../> <ImageView .../> <ImageView .../> </ScrollView> <LinearLayout android:layout_width="match_parent" android:layout_height="wrap_content" android:orientation="horizontal" > ... buttons ... </LinearLayout> </LinearLayout> 

Here's an answer with more information on the layout_weight attribute.

+1
source

Source: https://habr.com/ru/post/1388599/


All Articles