13

I have 3 text views in a layout, where the text clips a tad on the bottom on my droid 2... How can I ensure that the whole text is viewable, and the user can scroll down (simply with their finger), to see the rest of my text?

Thanks!

EDIT:

<?xml version="1.0" encoding="utf-8"?>


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

    <ImageButton android:id="@+id/ImageButton01" 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:background="@drawable/def" 
    android:layout_gravity="top|center">
    </ImageButton>

<TextView android:id="@+id/oneView" 
android:layout_width="wrap_content" 
android:layout_height="wrap_content" 
android:text="@string/one_def" 
android:layout_gravity="left|center" 
android:textSize="13dip"></TextView>

<TextView android:text="@string/two_def" 
android:layout_width="wrap_content" 
android:layout_height="wrap_content" 
android:layout_gravity="left|center" 
android:id="@+id/twoView" 
android:textSize="13dip"></TextView>

<TextView android:text="@string/threedef_def" 
android:layout_width="wrap_content" 
android:layout_height="wrap_content" 
android:layout_gravity="left|center" 
android:id="@+id/threeView" 
android:textSize="13dip"></TextView>


</LinearLayout>
Sapp
  • 1,793
  • 7
  • 29
  • 51

4 Answers4

27

Just wrap your current LinearLayout with ScrollView. So it should be smth like this:

<?xml version="1.0" encoding="utf-8"?>
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent">

    <LinearLayout
        android:orientation="vertical"
        android:layout_width="match_parent"
        android:layout_height="wrap_content">

        <ImageButton ... />
        <TextView ... />
        <TextView ... />
        <TextView ... />

    </LinearLayout>
</ScrollView>
Vit Khudenko
  • 28,288
  • 10
  • 63
  • 91
13

The direct child of ScrollView should be another layout that supports multiple children, such as RelativeLayout or LinearLayout.

Mike Yockey
  • 4,565
  • 22
  • 41
  • Can I potentially encapsulate a whole flipper as a scrollview? – Sapp Nov 23 '10 at 18:57
  • I don't think so, since the flipper itself isn't what you want to scroll. You want to scroll the content of the flipper members. Remember that some views in Android are already scrollable, most notably ListView; however, if you're utilizing non-scrolling views or canvases, you should assign multiple scroll views to your flipper. – Mike Yockey Nov 23 '10 at 19:00
  • I am really confused - I edited in my xml to see if you could show me what needs to be done to make this layout scrollable if it were to be too big for the screen – Sapp Nov 23 '10 at 19:17
2

Worked perfectly.

Here is my layout as an example of scrolling a content item with two headers above it that stay stationary.

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
android:id="@+id/mainMenu"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical"
android:background="#FFFFFFFF"
xmlns:android="http://schemas.android.com/apk/res/android"
>
    <FrameLayout
    android:id="@+id/widget112"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    >
        <ImageView
        android:id="@+id/chemo_pro_header"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:src="@drawable/chemo_pro_header"
        >
        </ImageView>
        <ImageButton
        android:id="@+id/menu_btn"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:src="@drawable/menu_btn_off"
        android:background="@null"
        android:layout_gravity="right"
        android:padding="8px"
        >
        </ImageButton>
    </FrameLayout>
    <ImageView 
    android:layout_width="wrap_content" 
    android:id="@+id/news_head"
    android:src="@drawable/news_head" 
    android:layout_height="wrap_content">
    </ImageView>
    <ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent">
        <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
        android:orientation="vertical"
        android:layout_width="fill_parent"
        android:layout_height="fill_parent">
            <TextView android:layout_marginLeft="6dip" android:text="Monday, November 29th, 2010" android:id="@+id/newsDateStamp" android:layout_width="wrap_content" android:layout_height="wrap_content" android:typeface="serif" android:textStyle="italic" android:textColor="#ff999999"></TextView>
            <TextView android:layout_marginLeft="6dip" android:text="Normal Article Titles Fit on These Lines and have room to be this long" android:textSize="16sp" android:typeface="serif" android:textStyle="bold" android:textColor="#ff000000" android:id="@+id/newsTitle" android:layout_width="wrap_content" android:layout_height="wrap_content"></TextView>
            <TextView android:layout_marginLeft="6dip" android:text="Article source" android:id="@+id/newsSource" android:layout_width="wrap_content" android:layout_height="wrap_content" android:typeface="serif" android:textStyle="italic" android:textColor="#ff999999"></TextView>
            <ImageView 
            android:layout_width="wrap_content" 
            android:id="@+id/news_image"
            android:src="@drawable/news_image" 
            android:layout_height="wrap_content" android:layout_gravity="center">
            </ImageView>
            <TextView android:text="Lorem ipsum dolor sit amet, consectetur adipiscing elit. Cras in volutpat enim. Donec tempus vestibulum risus in pellentesque. Etiam eget lorem at velit facilisis dapibus.\n\nNunc dolor sem, semper vel vestibulum eu, ultrices tempus augue. Donec ligula erat, tempor dignissim imperdiet et, rutrum sed nisi. Praesent dignissim nulla ullamcorper metus facilisis auctor. Duis elementum commodo dictum. Duis rhoncus hendrerit lectus in tincidunt. Ut est neque, rutrum ut auctor ac, aliquet ut massa. Nullam at felis ipsum. Curabitur adipiscing sodales massa, sed lobortis lectus ultrices quis. Integer lobortis cursus tellus sed tempus. Ut convallis ullamcorper interdum. Integer iaculis feugiat ultricies.\n\nNunc dolor sem, semper vel vestibulum eu, ultrices tempus augue. Donec ligula erat, tempor dignissim imperdiet et, rutrum sed nisi. Praesent dignissim nulla ullamcorper metus facilisis auctor. Duis elementum commodo dictum. Duis rhoncus hendrerit lectus in tincidunt. Ut est neque, rutrum ut auctor ac, aliquet ut massa." android:layout_marginTop="6dip" android:layout_marginBottom="6dip" android:typeface="serif" android:id="@+id/newsBody" android:layout_marginLeft="6dip" android:layout_height="wrap_content" android:layout_width="wrap_content" android:textColor="#ff000000" android:layout_marginRight="6dip"></TextView>
    </LinearLayout>
    </ScrollView>
</LinearLayout>
Johnsin
  • 21
  • 1
0

if you want to scroll entire layout just make scrollview the parent and make Linear layout or anyother layout as it's first child and then add other layouts inside that .... example:

<Scrollview>
   <LinearLayout  android:id="@+id/child1">
     <Textview />
     <Textview />
     <Button />
     <LinearLayout>
       <Textview />
     </LinearLayout>
   </LinearLayout>
 </scrollview>

here Scrollview has only one child 'child1' rest all are inside it and hence entire layout is scrollable.

MDhaked
  • 11
  • 3
Tushar Saha
  • 1,978
  • 24
  • 29