Reputation: 41
I have a problem with my ScrollView. I want to fit it inside the space available but i don´t know how.
Now i have my ScrollView and my TextView before one LinearLayout:
<ScrollView
android:id="@+id/scrollView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:fillViewport="true"
android:layout_alignParentLeft="true"
android:layout_below="@+id/previousimage"
android:layout_marginTop="@dimen/margin">
<TextView
android:id="@+id/question_text"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="@dimen/margintop"
android:gravity="center_horizontal"
android:paddingBottom="@dimen/margin_five"
android:scrollbars="vertical"
android:textColor="@color/white"
android:textSize="@dimen/common_textsize" />
</ScrollView>
<LinearLayout
android:id="@+id/bottom_options"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_below="@+id/scrollView"
android:layout_marginTop="@dimen/margin_small"
android:gravity="center|bottom"
android:orientation="vertical">
The problem is that if i have so much text inside my TextView the LinearLayout go down and it hides.I want to scroll the text inside. Without push down the LinearLayout.
I want to take this space for ScrollView automatically to adapt to all screen size.
Thank you!
Upvotes: 1
Views: 2719
Reputation: 2904
Define LinearLayout before your ScrollView and set ScrollView to above LinearLayout, match_parent. Like this:
<LinearLayout
android:id="@+id/bottom_options"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_marginTop="@dimen/margin_small"
android:gravity="center|bottom"
android:orientation="vertical">
...
</LinearLayout>
<ScrollView
android:id="@+id/scrollView"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_weight="1"
android:fillViewport="true"
android:layout_alignParentLeft="true"
android:layout_below="@+id/previousimage"
android:layout_above="@+id/bottom_options"
android:layout_marginTop="@dimen/margin">
<TextView
android:id="@+id/question_text"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="@dimen/margintop"
android:gravity="center_horizontal"
android:paddingBottom="@dimen/margin_five"
android:scrollbars="vertical"
android:textColor="@color/white"
android:textSize="@dimen/common_textsize" />
</ScrollView>
Upvotes: 4
Reputation: 1636
The ScrollView should always match_parent
(or at least be smaller than the available space) otherwise it just take the same space as its children and so from its perspective, no children is out, so no need to scroll.
Upvotes: 0