Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Non stretching ScrollView

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?

like image 684
Solvek Avatar asked Mar 03 '11 10:03

Solvek


People also ask

What is fillViewport in ScrollView?

android:fillViewport. Defines whether the scrollview should stretch its content to fill the viewport.

What is the difference between ScrollView and horizontal ScrollView?

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.

Is ScrollView a Viewgroup?

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.

What is the difference between ScrollView and ListView?

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.


1 Answers

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>
like image 60
pankajagarwal Avatar answered Sep 30 '22 08:09

pankajagarwal