Textview, Automobile Scroll Downwards To Display Bottom Of Text

Posted on

This representative exhibit how to brand a TextView auto scroll downwardly to display bottom of text. In the demonstration, the upper TextView is normal, user cannot meet the bottom of text if it is full. The lower one, the TextView volition car scroll down, such that user tin meet the novel added text.

<?xml version="1.0" encoding="utf-8"?> <LinearLayout 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:padding="16dp"     android:orientation="vertical"     tools:context="com.blogspot.android_er.androidautotextview.MainActivity">      <TextView         android:layout_width="wrap_content"         android:layout_height="wrap_content"         android:layout_margin="20dp"         android:layout_gravity="center_horizontal"         android:autoLink="web"         android:text="https://rootandroid.org//"         android:textStyle="bold"/>      <EditText         android:id="@+id/textin"         android:layout_width="match_parent"         android:layout_height="wrap_content"         android:textSize="28dp"/>      <Button         android:id="@+id/btnappend"         android:layout_width="match_parent"         android:layout_height="wrap_content"         android:text="Append Text"/>      <LinearLayout         android:layout_width="match_parent"         android:layout_height="match_parent"         android:orientation="vertical">         <TextView             android:id="@+id/textout1"             android:layout_width="match_parent"             android:layout_height="0dp"             android:layout_weight="1"             android:textSize="20dp"             android:background="#D0D0D0"/>         <TextView             android:id="@+id/textout2"             android:layout_width="match_parent"             android:layout_height="0dp"             android:layout_weight="1"             android:textSize="20dp"             android:gravity="bottom"             android:background="#E0E0E0"/>     </LinearLayout>  </LinearLayout>  

package com.blogspot.android_er.androidautotextview;  import android.os.Bundle; import android.support.v7.app.AppCompatActivity; import android.text.method.ScrollingMovementMethod; import android.view.View; import android.widget.Button; import android.widget.EditText; import android.widget.TextView;  populace class MainActivity extends AppCompatActivity {      EditText editTextIn;     TextView textViewOut1, textViewOut2;     Button btnAppend;      @Override     protected void onCreate(Bundle savedInstanceState) {         super.onCreate(savedInstanceState);         setContentView(R.layout.activity_main);          editTextIn = (EditText)findViewById(R.id.textin);         btnAppend = (Button)findViewById(R.id.btnappend);          textViewOut1 = (TextView)findViewById(R.id.textout1);         textViewOut1.setText("It's normal TextView.\n");          textViewOut2 = (TextView)findViewById(R.id.textout2);         textViewOut2.setMovementMethod(new ScrollingMovementMethod());         textViewOut2.setText("This TextView e'er car scroll downwardly to display bottom of text.\n");           btnAppend.setOnClickListener(new View.OnClickListener() {             @Override             populace void onClick(View view) {                 String textToAppend = editTextIn.getText().toString() + "\n";                 textViewOut1.append(textToAppend);                 textViewOut2.append(textToAppend);                 editTextIn.setText("");             }         });     } }