1

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.

See the image Layaout

Thank you!

user3777879
  • 41
  • 1
  • 10

2 Answers2

4

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>
Karim Aly
  • 559
  • 5
  • 16
i_A_mok
  • 2,744
  • 2
  • 11
  • 15
  • Thank you! this work perfect! now i have a problem with "TextView" and text inside. It show text at the bottom and i want show it in the center of the ScrollView. – user3777879 Jul 26 '16 at 09:44
  • Both ScrollView and TextView has "android:layout_marginTop". I think it is duplicated and so you text goes to the bottom. In addition, if you want to have text "center_horizontal", then you need to change, android:layout_width to "match_parent". – i_A_mok Jul 27 '16 at 03:30
0

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.

Vadim Caen
  • 1,526
  • 11
  • 21
  • If i setup in ScrollView this: android:layout_width="match_parent" android:layout_height="match_parent" then the LinearLayout hides completely. – user3777879 Jul 25 '16 at 23:14
  • Your linear layout is empty so its height will be 0. If you need to display LinearLayout under the ScrollView, you should embed them into a parent a layout. – Vadim Caen Jul 25 '16 at 23:16
  • LinearLayout is filled but i have not pasted the content. Now i have this. http://i.stack.imgur.com/zo04x.png But if i have so much text. ScrollView does´t work and push my LinearLayout outside of screen. – user3777879 Jul 25 '16 at 23:22