Non-Stretching ScrollView

I have scroll in liner layout, here is my layout file

<LinearLayout android:orientation="vertical" android:layout_width="fill_parent" android:layout_height="wrap_content"> <!-- Other widgets go here --> <ScrollView android:layout_width="fill_parent" android:layout_height="wrap_content"> <!-- Scroll view content --> </ScrollView> </LinearLayout> 

I want the height of the ScrolView to depend on its contents - wrap it, however, if this height makes the height of the whole layout more than that screen size, it needs to be fixed to fit the height of the screen. How can this be achieved?

+4
source share
2 answers

If you want scrollview to fill the entire screen, even if there is not enough data to do this, try this instead

 <LinearLayout android:orientation="vertical" android:layout_width="fill_parent" android:layout_height="fill_parent"> <!-- Other widgets go here --> <ScrollView android:layout_width="fill_parent" android:layout_height="wrap_content" android:fillViewport="true"> <!-- Scroll view content --> </ScrollView> </LinearLayout> 
+6
source

add this as an attribute in scrollview

 android:fillViewport="true" 
-1
source

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


All Articles