1

I designed a simple layout for my test App, a TextView, then a ImageView and a TextView. But the second TextView I want it scrollable (by touch).

I have searched and tried many solutions on the net but still can't make it work.

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:paddingBottom="@dimen/activity_vertical_margin"
    android:paddingLeft="@dimen/activity_horizontal_margin"
    android:paddingRight="@dimen/activity_horizontal_margin"
    android:paddingTop="@dimen/activity_vertical_margin"
    android:scrollbars="vertical"
    tools:context=".MainActivity" >

    <TextView
        android:id="@+id/title"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_centerHorizontal="true"
        android:text="@string/title"
        android:textSize="40sp"
        android:textStyle="bold" />


        <ImageView
        android:id="@+id/imageView1"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_below="@id/title"
        android:layout_centerHorizontal="true"
        android:adjustViewBounds="true"
        android:contentDescription="@string/ada_lovelace"
        android:paddingTop="8dp"
        android:src="@drawable/ada_lovelace" />

    <ScrollView 
        android:layout_height="fill_parent"
        android:layout_width="wrap_content"
        android:id="@+id/scroll1"
        android:layout_below="@id/imageView1">  

        <TextView
            android:id="@+id/textView1"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:paddingTop="8dp"
            android:text="@string/hello_world"
            android:textSize="22sp" />


    </ScrollView>


</RelativeLayout>

Please help me.

Vivek Warde
  • 1,936
  • 8
  • 47
  • 77
user3189534
  • 19
  • 1
  • 2
  • It works only if the textview has more elements to scroll – Viswanath Lekshmanan Jan 13 '14 at 12:05
  • Refer to this link, it has solved my problem.... http://stackoverflow.com/questions/1748977/making-textview-scrollable-in-android.. – krishna Jan 13 '14 at 12:06
  • Use ListView and easy Adapter – user1755546 Jan 13 '14 at 12:07
  • plz check adding more content in your second textview – Sanket990 Jan 13 '14 at 12:08
  • 1
    ScrollView works only if inner layout exceed the size of the ScrollView itself. Let me give an example. Let's say that you have a ScrollView which has 100dp height and fill_parent width. And it has a TextView which has 150dp height and wrap_content width. Since ScrollView has 100dp height, your TextView will be scrollable vertically 50dp. So in your example, since your word is, probably default by "Hello world!" does not exceed your ScrollView size (note that your ScrollView height is screen size), it won't scroll. – Barışcan Kayaoğlu Jan 13 '14 at 12:12

10 Answers10

0

You don't need a ScrollView for the TextView, TextView has the scrolling attribute.

Try setting it and see whether it works.

Ferrmolina
  • 2,737
  • 2
  • 30
  • 46
nKn
  • 13,691
  • 9
  • 45
  • 62
0

You can use this link. And the format of using scrollview in xml is below:

  <linearlayout>
      <scrollview>
        <linear>or <relativelayout>
        </linear layout>
      </scrollview>
  </linear layout>.
Community
  • 1
  • 1
rajshree
  • 790
  • 5
  • 19
0
  1. Set the ScrollView's height to 38dp.
  2. Set the TextView's size to 40sp.

Then you can scroll the TextView.

anjaneya
  • 708
  • 9
  • 11
0

Scrolling works only when a part of its child is not visible in the screen due to large size or large numbers

Athul
  • 231
  • 1
  • 7
0

I had the same problem some weeks ago, and this was my solution:

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

    <RelativeLayout
        android:id="@+id/RelativeLayout2"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:orientation="vertical" >

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

But if there is not "enough" content in the TextView, it is not scrollable. Only if its more than your screen kann "capture".

Fraggles
  • 463
  • 4
  • 20
  • Still not work with me. The hello_world string I had change to some paragraph and it's long enough to have a scroll but it doesn't move :( – user3189534 Jan 13 '14 at 15:26
0

Everything works fine after I re-import my project. I don't know what error is this but maybe it's because of eclipse faulty.

user3189534
  • 19
  • 1
  • 2
0

Instead of using ScrollView for your TextView, you can make you TextView scrollable using the following code.

<TextView
    android:id="@+id/txtView"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:maxLines="5"
    android:scrollbars="vertical"
    android:textAppearance="?android:attr/textAppearanceSmall" />

And in you Java file use this code

txtView.setMovementMethod(new ScrollingMovementMethod());

Hope this will help.

Abhishek Dhiman
  • 1,631
  • 6
  • 25
  • 38
0

Scrollable becomes only the part which is in between ScrollView

So if you want to scroll everything (And as I understood you do) you just need to change the sequence. I also believe that ScrollView needs to be in layout and have a layout, so you need two layouts: one inside and one out side.Though I'm not sure about last sentence - I'm just starting to learn stuff

King_Z
  • 41
  • 1
  • 1
  • 4
0

Here is your solution implement this code and run the code textview is scrollable.

<ImageView
    android:id="@+id/imageView1"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_below="@id/title"
    android:layout_centerHorizontal="true"
    android:adjustViewBounds="true"
    android:contentDescription="@string/ada_lovelace"
    android:paddingTop="8dp"
    android:src="@drawable/ada_lovelace" />

<ScrollView
    android:layout_height="fill_parent"
    android:layout_width="wrap_content"
    android:id="@+id/scroll1"
    android:layout_below="@id/imageView1">

    <RelativeLayout
        android:layout_width="match_parent"
        android:layout_height="match_parent">

    <TextView
        android:id="@+id/textView1"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:paddingTop="8dp"
        android:text="@string/hello_world"
        android:textSize="22sp" />

    </RelativeLayout>
</ScrollView>

Akhil0181
  • 14
  • 8
0

It should work please try

<ScrollView
android:layout_width="fill_parent"
android:layout_height="wrap_content" 
android:padding_bottom = "10dp">
<TextView
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:text="@string/textview" />
</ScrollView>
Tanmay Sahoo
  • 471
  • 1
  • 6
  • 16