Making Textview Scrollable on Android

Making TextView scrollable on Android

You don't need to use a ScrollView actually.

Just set the

android:scrollbars = "vertical"

properties of your TextView in your layout's xml file.

Then use:

yourTextView.setMovementMethod(new ScrollingMovementMethod());

in your code.

Bingo, it scrolls!

How to make a TextView scrollable in a fragment?

I would suggest to use ScrollView:

<ScrollView
android:layout_width="0dp"
android:layout_height="0dp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
android:orientation="vertical">

<TextView
android:id="@+id/atomicNumberDefinition"
android:text="The atomic number..... "
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textColor="#000000"
android:textSize="24sp" />
</ScrollView>

how to make Textview scrollable and also make it swipeable in android

Scrollable TextView: Put the TextView as the child of a ScrollView.

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

<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Hello World!" />
</ScrollView>

Remember that a ScrollView can only hold ONE object.

For Gestures, look at Detecting Common Gestures

EDIT:

You can also use this line of code in the XML and see if it works (with the textview):

android:scrollbars="vertical"

How can I make a TextView automatically scroll as I add more lines of text?

As per answer here Making TextView Scrollable in Android

You don't need to use a ScrollView actually.

Just set the

android:maxLines = "AN_INTEGER"

android:scrollbars = "vertical"
properties of your TextView in your layout's xml file.

Then use:

yourTextView.setMovementMethod(new ScrollingMovementMethod());

in your code.

That will work..



Related Topics



Leave a reply



Submit