How to Make Scrollable TextView in Android
Android TextView allows user to display text in android application. In
this tips, I will show how to make scrollable TextView in android. To
make TextView scrollable, you don’t need to use ScrollView, just add android:scrollbars=”vertical” attribute in TextView and then add two line of code in your java activity file.
XML Layout File
Following is the xml layout file which contain a LinearLayout and a TextView.
res/layout/scrollable_textview.xml
Java Activity File
Following is the final code of MainActivity.java file.
src/MainActivity.java
Now, run your application and see texts are scrolling.
Output:
XML Layout File
Following is the xml layout file which contain a LinearLayout and a TextView.
res/layout/scrollable_textview.xml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?xml version="1.0" encoding="utf-8"?> | |
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" | |
android:layout_width="match_parent" | |
android:layout_height="match_parent" | |
android:orientation="vertical"> | |
<TextView | |
android:id="@+id/text_view" | |
android:layout_width="match_parent" | |
android:layout_height="match_parent" | |
android:scrollbars="vertical" | |
android:layout_margin="16dp" | |
android:text="Scrollable TextView in android application, how to make android textview scroollable without using scrollview. Scrollable TextView in android application, how to make android textview scroollable without using scrollview. Scrollable TextView in android application, how to make android textview scroollable without using scrollview. Scrollable TextView in android application, how to make android textview scroollable without using scrollview. Scrollable TextView in android application, how to make android textview scroollable without using scrollview. Scrollable TextView in android application, how to make android textview scroollable without using scrollview. Scrollable TextView in android application, how to make android textview scroollable without using scrollview. Scrollable TextView in android application, how to make android textview scroollable without using scrollview. Scrollable TextView in android application, how to make android textview scroollable without using scrollview. Scrollable TextView in android application, how to make android textview scroollable without using scrollview. Scrollable TextView in android application, how to make android textview scroollable without using scrollview. Scrollable TextView in android application, how to make android textview scroollable without using scrollview. Scrollable TextView in android application, how to make android textview scroollable without using scrollview. Scrollable TextView in android application, how to make android textview scroollable without using scrollview. Scrollable TextView in android application, how to make android textview scroollable without using scrollview. Scrollable TextView in android application, how to make android textview scroollable without using scrollview. Scrollable TextView in android application, how to make android textview scroollable without using scrollview. " /> | |
</LinearLayout> |
Java Activity File
Following is the final code of MainActivity.java file.
src/MainActivity.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package com.droidinsider.androidshorttutorial; | |
import android.os.Bundle; | |
import android.support.v7.app.AppCompatActivity; | |
import android.text.method.ScrollingMovementMethod; | |
import android.widget.TextView; | |
public class MainActivity extends AppCompatActivity { | |
@Override | |
protected void onCreate(Bundle savedInstanceState) { | |
super.onCreate(savedInstanceState); | |
setContentView(R.layout.scrollable_textview); | |
TextView textView = (TextView) findViewById(R.id.text_view); | |
textView.setMovementMethod(new ScrollingMovementMethod()); | |
} | |
} |
Now, run your application and see texts are scrolling.
Output:
Comments
Post a Comment