Skip to content

Android Scrollable TextView | Vertical Using XML and Programmatically

Making TextView scrollable on Android you need to use a android:scrollbars properties of your TextView in your layout’s XML file.

Then use the below code in the Activity file. This method will enable scrolling on TextView.

Kotlin

text_v1.setMovementMethod(ScrollingMovementMethod())

Java

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

ScrollView is needed when you want to show too long text and should fit into one screen.

Complete code of Android Scrollable TextView

Let’s build an app and demonstrates it, Here is the complete step by step tutorial:-

Step 1. Create an android project in the android studio (Follow this tutorial: Android First Program in Android Studio).

Step 2. Open the strings.xml file.

Android Long in scroll Using XML

Step 3. Add your long text in the strings.xml file.

You can add your own text, this is only for testing purpose.


    Android Scrollable TextView
    WordPress is easy to make website without a technical knowledge person also can build the awesome websites.
15 years ago you need to learn HTML, CSS for only static website and for dynamic  or e-commerce site need more like Javascript and database.
Wordpress is free and open source content management system.
It has largest community.
You can install a WordPress within a minute in web host.
Wordpress main feature is plugins. Which extends a feature of website without hard work.
Then another feature is templets (them) can change only on one click.
Initial release date: 27 May 2003
Written in: PHP
Stable and current version : 5.0.5 (19-Dec-2018)
Top websites in WordPress : Sony Music, CNN, starwars.com, news.microsoft.com, techcrunch.com.

Introduction

Who used a WordPress ?

Wordpress site has written in more then 120 languages and
every day 10 thousand site created.

Why Use a WordPress?

Its a Free and open source
You will get a admin panel an editor
A very powerful
Largest community
Can use and handle different media like images, video, gif etc.
Its a search engine friendly (SEO) google like it because it done work for SEO almost 90-95%.
Wordpress easy to manage your site
It’s secure - Need some setup
Can create any type of website with WordPress.
You can also create responsive and mobile friendly site - Based on theme used
You have to just setup one time as technical aspect



How to setup

You can install WordPress on Computer or WebHost
WebHost - For if you want a available website to other (Online)
LocalHost - On your computer if you want learn WordPress and don’t want invest money in Hosting.
Get the domain name
Install the WordPress



Step 4. Add the below code in activity_main.xml

Setting the height of TextView 300dp to see how it works.

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical"
    tools:context=".MainActivity">

    <TextView
        android:id="@+id/text_v1"
        android:layout_width="wrap_content"
        android:layout_height="300dp"
        android:background="#E6E6A1"
        android:padding="10dp"
        android:scrollbars="vertical"
        android:text="@string/txt"
        android:textSize="20dp" />

</LinearLayout>

Step 5. Add the below code in MainActivity.kt

For java, you can use it from the tutorial top section.

package com.eyehunts.androidscrollabletextview

import android.os.Bundle
import android.text.method.ScrollingMovementMethod
import androidx.appcompat.app.AppCompatActivity
import kotlinx.android.synthetic.main.activity_main.*


class MainActivity : AppCompatActivity() {

    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        setContentView(R.layout.activity_main)

        //vertical
        text_v1.setMovementMethod(ScrollingMovementMethod())
    }
}

Step 4. Now Run the application, in an emulator or on your Android device.

Output screenshot Android Scrollable TextView:-

Android Scrollable TextView

Download Link and Source of Scrollable TextView Android kotlin code in Github

https://github.com/EyeHunts/AndroidScrollableTextView

Do comment if you have any doubts or suggestions on this tutorial.

Note: This example (Project) is developed in Android Studio 3.3.2. Tested on Android 9 ( Android-P), compile SDK version API 28: Android 9.0 (Pie)
MinSdkVersion=25″
TargetSdkVersion=28″Coding in Kotlin

2 thoughts on “Android Scrollable TextView | Vertical Using XML and Programmatically”

Leave a Reply

Your email address will not be published.

This site uses Akismet to reduce spam. Learn how your comment data is processed.