1

i have the following layout in xml

<Relativelayout.....
       <TextView 1........../>

       <ImageView........./>

       <Textview 2......../>
</Relativelayout>

I need to add vertical scrollview to Textview 2 how to do this i have added the foll code but not working...

<LinearLayout>

   <ScrollView >

      <TextView />

   </ScrollView> 
</LinearLayout>

please help

Goofy
  • 5,990
  • 17
  • 83
  • 152
  • If you simply want to scroll a textview, why dont you use TexViewObject.setMovementMethod(new ScrollingMovementMethod()) as suggested in this http://stackoverflow.com/questions/1748977/making-textview-scrollable-in-android – Kartik Domadiya Feb 28 '12 at 11:47

4 Answers4

2

In your activity Do something like this:

TextView textDisplayed =(TextView) findViewById(R.id.textView1);
textDisplayed.setMovementMethod(new ScrollingMovementMethod());

Hope this helps.

Deva
  • 3,809
  • 22
  • 36
  • just add this in layout android:maxLines and android:scrollbars = "vertical" properties of textview in layout xml file. Then use the TexView.setMovementMethod(new ScrollingMovementMethod()) in .java – Goofy Feb 28 '12 at 11:58
  • thanks it worked for me also i also commented what should be added in .java so that it works perfectly – Goofy Feb 28 '12 at 11:59
0

Add a ViewGroup (like LinearLayout) between the ScrollView and your TextView. AFAIK, it's mandatory.

Sly
  • 2,065
  • 5
  • 21
  • 28
0
<?xml version="1.0" encoding="utf-8"?>

<ScrollView
    android:id="@+id/scrollView1"
    android:layout_width="match_parent"
    android:layout_height="wrap_content" >

    <LinearLayout
        android:id="@+id/linearLayout1"
        android:layout_width="match_parent"
        android:layout_height="match_parent" >


        <EditText
            android:id="@+id/editText1"
            android:layout_width="wrap_content"
            android:layout_height="352dp"
            android:layout_weight="1"
            android:inputType="textMultiLine" >

            <requestFocus />
        </EditText>

    </LinearLayout>
</ScrollView>

this works for me

Orlymee
  • 2,325
  • 1
  • 20
  • 24
  • But it showing NULLpointer exception for me as its not able to find the texview id which is inside LL – Goofy Feb 28 '12 at 11:48
  • sorry the order should be different, LinearLayout->scrolliew->textview. are you sure calling the textview correctly in your code TextView tv = (TextView)findViewById(R.id.editText1); – Orlymee Feb 28 '12 at 11:54
  • yes thanks for your help i got the answer please see the answer accepted – Goofy Feb 28 '12 at 12:23
0

this is absolutely fine to add scroview on textView but keep one thing in mind only height of textview should be more then scroll view height

<LinearLayout>

   <ScrollView >

      <TextView /> //textView 2

   </ScrollView> 
</LinearLayout>
vipin
  • 2,531
  • 3
  • 16
  • 32