I have a scroll view inside a 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 ScrolView's height was dependent to its content - wrap it, however if this height makes the whole layout height more that screen size it should be fixed to fit screen's height. How can achive it?
android:fillViewport. Defines whether the scrollview should stretch its content to fill the viewport.
Attributes Of Scroll View: ScrollView and HorizontalScrollView has same attributes, the only difference is scrollView scroll the child items in vertical direction while horizontal scroll view scroll the child items in horizontal direction.
In Android, a ScrollView is a view group that is used to make vertically scrollable views. A scroll view contains a single direct child only. In order to place multiple views in the scroll view, one needs to make a view group(like LinearLayout) as a direct child and then we can define many views inside it.
ScrollView is used to put different or same child views or layouts and the all can be scrolled. ListView is used to put same child view or layout as multiple items. All these items are also scrollable. Simply ScrollView is for both homogeneous and heterogeneous collection.
If you want the scrollview to fill the entire screen even if the data isn't enough to do so then 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>
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With