0

I would like to have a TextView on top where if it was more then 5 lines of text, it would scroll. Then a list of text on the bottom that simply files the remain space.

I'm using the ScrollView with a TextView inside. The problem is if I set the top scroll to warp content, it will keep getting bigger if there is more then 5 lines of text. If I set it to fill parent, the button text view will not get displayed. Is there a way to do this?

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical" >

    <TextView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="Tell a Furtune Chat"
        android:textSize="38px" />

    <ScrollView
        android:layout_width="fill_parent"
        android:layout_height="wrap_content" >

        <TextView
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="Tell a Furtune \n ted \n teda \n rob \n fred \n bed \n jack \n junk \n more"
            android:textSize="38px" />
    </ScrollView>

    <ScrollView
        android:layout_width="fill_parent"
        android:layout_height="wrap_content" >

        <TextView
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="Tell a Furtune \n ted \n teda \n rob \n fred \n bed \n jack \n junk \n more"
            android:textSize="38px" />
    </ScrollView>

</LinearLayout>
Sam
  • 84,460
  • 18
  • 172
  • 171
Ted pottel
  • 6,503
  • 16
  • 67
  • 124

1 Answers1

0

If I understand your question, simply use this attribute:

<TextView
    ...
    android:maxLines="5" />

Also, if your ScrollViews are "pushing" other views off the bottom of the screen you can limit their height like this:

<ScrollView
    ...
    android:height="100dp" >

Addition

From the Documentation:

EditText is a thin veneer over TextView that configures itself to be editable.

However in this case: maxLines behaves in two very different manners. I seemed to remember that a TextView would scroll automatically after defining maxLines just like the EditTexts that I use on a regular basis. (What a crazy thought!) Anyway, this is the easiest way to achieve what you want:

<ScrollView
    android:layout_width="wrap_content"
    android:layout_height="90sp" >

    <TextView
        android:id="@+id/text"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        ... />
</ScrollView>

Where the ScrollView's height is a ratio of the font size to how many row you want displayed. You can use the maxLines attribute as described here ( Making TextView scrollable on Android ), but this solution does not support fling gestures and creates a "blink" effect whenever the user scrolls.

Community
  • 1
  • 1
Sam
  • 84,460
  • 18
  • 172
  • 171
  • Hi,I want the list box to show a max of 5 lines, so after 5 lines you will be able to scroll to see all the lines and the controls below it will not get push down, – Ted pottel Jun 14 '12 at 16:13