Android: ScrollView Issue

37,509

Solution 1

Your EditText should have a height of wrap_content. fill_parent has no meaning in a ScrollView. If you want the EditText to fill your ScrollView when it's content is smaller than the ScrollView, use android:fillViewport="true" on the ScrollView.

Solution 2

Yes, as Romain said, scrollview needs following combo.

  1. for ScrollView android:fillViewport="true"
  2. for child of ScrollView android:layout_height="wrap_content"
Share:
37,509
Niko Gamulin
Author by

Niko Gamulin

Engineer/Researcher, working in the field of Machine Learning.

Updated on August 25, 2020

Comments

  • Niko Gamulin
    Niko Gamulin over 3 years

    I have had a number of problems with ScrollViews. Recently I tried to create a LinearView which content exceeds the screen size so I created the new layout with parent element ScrollView and set its width and height to custom values (the layout has to appear as dialog - not filling the whole screen).

    When the element is selected the red border appears to embrace the rectangle of predefined ScrollView LayoutWidth and LayoutHeight which is OK. Then I placed inside the LinearView and set the values LayoutWidth and LayoutHeight to fill_parent.

    Then when I started to add the elements into the LinearLayout the border (red lile) wrapped the inserted elements, not the whole parent ScrollView.

    So when the content of the LinearLayout (child of ScrollView) exceeded the size of parent ScrollView the scroll didn't appear and the bottom elements are simply invisible.

    Anyway.. in that case the XML content was too extensive to post the question here and now I'm having the same problem with the more simple example.

    The following part of the layout is intended to be a scrollable EditText (in case the user input exceeds the primary size of the widget). I wanted to set the EditText height to 120px, so I set the parent ScrollView height to 120px and the child EditText to fill_parent. Again in this case the EditText doesn't fill the whole ScrollView area but a single line:

     <ScrollView android:layout_height="120px" android:layout_width="fill_parent">
    <EditText android:id="@+id/txtContent" android:layout_height="fill_parent" android:layout_width="fill_parent" android:text="TestContent">
    </EditText>
    </ScrollView>
    

    Does anyone know how to reshape the content above so the EditText fills the parent control and in case the user's input exceeds the control size the scroll appears?

    Thank you!

    Edit:

    Below are the screenshots of the layout

    removed dead ImageShack link
    removed dead ImageShack link