user3127054
user3127054

Reputation:

I want to scroll only a TextView

I'm developing a Stopwatch Application.

I want to scroll only a TextView.

Here's XML file.

activity_main.xml

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="#001729"
android:orientation="vertical" >



<Button
    android:id="@+id/btn_rec"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:layout_alignParentBottom="true"
    android:layout_alignParentLeft="true"
    android:enabled="false"
    android:onClick="myOnClick"
    android:text="Record" />

<Button
    android:id="@+id/btn_start"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:layout_above="@+id/btn_rec"
    android:layout_alignParentLeft="true"
    android:onClick="myOnClick"
    android:text="Start" />


**<TextView
    android:id="@+id/record"
    android:layout_width="fill_parent"
    android:layout_height="500dp"
    android:layout_below="@+id/time_out"
    android:layout_above="@+id/btn_start"
    android:layout_alignParentLeft="true"
    android:padding="10dp"
    android:textColor="#FFFFFF"
    android:textSize="20sp" />**


<TextView
    android:id="@+id/time_out"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:layout_alignParentLeft="true"
    android:layout_below="@+id/relativeLayout1"
    android:layout_marginTop="37dp"
    android:gravity="center"
    android:text="00:00:00"
    android:textColor="#FFFFFF"
    android:textSize="60sp" />

I want to scroll only TextView in bold.

I don't know how to use ScrollView in this case.

How can I do? thanks :)

Upvotes: 0

Views: 517

Answers (5)

gilonm
gilonm

Reputation: 1859

In your XML (inside TextView) you might want to set the attribute:

android:minLines="2"
android:maxLines="5"

In that way you define the min and max line numbers in your textview, and only that will scroll.

Read here too:

minLines

maxLines

Upvotes: 0

Gopal Gopi
Gopal Gopi

Reputation: 11131

you can scroll TextView (i.e. text inside TextView) using marquee property.

<TextView
    android:id="@+id/textView"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:scrollbars="vertical"
    android:marqueeRepeatLimit="marquee_forever"
    android:text="@string/hello_world" />

and programmatically

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

Upvotes: 1

Vivek Warde
Vivek Warde

Reputation: 1514

Set the parent of RelativeLayout as ScrollView as ScrollView can only have 1 direct child ! or copy paste this-

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="#001729"  
 >

<ScrollView 
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="#001729"
>

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




<Button
android:id="@+id/btn_rec"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_alignParentLeft="true"
android:enabled="false"
android:onClick="myOnClick"
android:text="Record" />

<Button
android:id="@+id/btn_start"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_above="@+id/btn_rec"
android:layout_alignParentLeft="true"
android:onClick="myOnClick"
android:text="Start" />


<TextView
android:id="@+id/record"
android:layout_width="fill_parent"
android:layout_height="500dp"
android:layout_below="@+id/time_out"
android:layout_above="@+id/btn_start"
android:layout_alignParentLeft="true"
android:padding="10dp"
android:textColor="#FFFFFF"
android:textSize="20sp" />**


<TextView
android:id="@+id/time_out"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_below="@+id/relativeLayout1"
android:layout_marginTop="37dp"
android:gravity="center"
android:text="00:00:00"
android:textColor="#FFFFFF"
android:textSize="60sp" />

</LinearLayout>
<ScrollView>
</RelativeLayout>

this will scroll all the TextView(s) placed inside the RelativeLayout

Upvotes: 0

Michael Yaworski
Michael Yaworski

Reputation: 13483

You can replace your TextView with this:

<ScrollView
    android:layout_width="fill_parent"
    android:layout_height="500dp"
    android:padding="10dp"
    android:layout_above="@+id/btn_start"
    android:layout_alignParentLeft="true"
    android:layout_below="@+id/time_out" >

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

        <TextView
            android:id="@+id/record"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:textColor="#FFFFFF"
            android:textSize="20sp" />
    </RelativeLayout>
</ScrollView>

All I did was wrap it in a RelativeLayout, and then wrap that in a ScrollView. I also put the layout properties of the TextView into the ScrollView, because now the ScrollView is the parent. I chose to do a RelativeLayout because the other answer chose a LinearLayout. It doesn't really matter.

Note you may have to play around with a few of the properties. The idea is there though. It should work out.

Upvotes: 0

keshav
keshav

Reputation: 3255

Replace your textview with this

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

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

            <TextView
                android:id="@+id/textView1"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"

                android:text="@string/hello_world" />
        </LinearLayout>
    </ScrollView>

Upvotes: 0

Related Questions