android - Automatic scrolling the text vertically -


how can scrolled automatically in vertical manner till end of texts? code stops after time , not reach end. , want start scrolling till end after clicking button. suffice.

activity_main.xml

<relativelayout 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:paddingbottom="@dimen/activity_vertical_margin"             android:paddingleft="@dimen/activity_horizontal_margin"             android:paddingright="@dimen/activity_horizontal_margin"             android:paddingtop="@dimen/activity_vertical_margin"             tools:context=".mainactivity" > <button     android:id="@+id/button1"     style="?android:attr/buttonstylesmall"     android:layout_width="wrap_content"     android:layout_height="wrap_content"     android:layout_below="@+id/textview1"     android:layout_alignparentright="true"     android:text="ok" /> <scrollview     android:id="@+id/scrollview1"     android:layout_width="wrap_content"     android:layout_height="wrap_content"     android:layout_centerhorizontal="true" >      <textview         android:text="@string/random_text"         android:id="@+id/textview1"         android:ellipsize="marquee"         android:marqueerepeatlimit ="marquee_forever"         android:focusable="true"         android:scrollbars="vertical"         android:focusableintouchmode="true"         android:maxlines="4"         android:layout_width="wrap_content"         android:layout_height="wrap_content"/>  </scrollview> </relativelayout> 

mainactivity.java

package com.bhabani2077.autoscroll;  import android.support.v7.app.appcompatactivity; import android.os.bundle; import android.support.v7.widget.toolbar; import android.text.method.scrollingmovementmethod; import android.view.view; import android.view.animation.linearinterpolator; import android.widget.button; import android.widget.edittext; import android.widget.scrollview; import android.widget.scroller; import android.widget.textview;  public class mainactivity extends appcompatactivity { toolbar mtoolbar; // edittext medittext; button mbutton; textview mtextview; scroller mscroller;  @override protected void oncreate(bundle savedinstancestate) {     super.oncreate(savedinstancestate);     setcontentview(r.layout.activity_main);     mtoolbar= (toolbar) findviewbyid(r.id.toolbar);     setsupportactionbar(mtoolbar);   //  medittext= (edittext) findviewbyid(r.id.edittext1);     mbutton= (button) findviewbyid(r.id.button1);     mtextview= (textview) findviewbyid(r.id.textview1);     mtextview.setselected(true);     mtextview.setmovementmethod(new scrollingmovementmethod());     mscroller=new scroller(mainactivity.this,new linearinterpolator());     mtextview.setscroller(mscroller);     mscroller.startscroll(0,0,0,500,5000);      mbutton.setonclicklistener(new view.onclicklistener() {         @override         public void onclick(view v) {             //if (medittext.gettext().length()>0){             //    mtextview.append(medittext.gettext()+"\n");              //   medittext.settext("");              }     });  }  } 

i think found fix on own. created custom textview class scroller method , linked xml code. have look,

autoscrollingtext.java

public class autoscrollingtext extends textview {      private static final float default_speed = 9.0f;      public scroller scroller;     public float speed = default_speed;     public boolean continuousscrolling = true;      public autoscrollingtext(context context) {         super(context);       scrollerinstance(context);     }      public autoscrollingtext(context context, attributeset attributes) {         super(context, attributes);        scrollerinstance(context);     }      public void scrollerinstance(context context) {         scroller = new scroller(context, new linearinterpolator());         setscroller(scroller);     }       @override     protected void onlayout(boolean changed, int left, int top, int right, int bottom) {         super.onlayout(changed, left, top, right, bottom);         if (scroller.isfinished()) {            scroll();         }     }      public void scroll() {         int viewheight = getheight();         int visibleheight = viewheight - getpaddingbottom() - getpaddingtop();         int lineheight = getlineheight();          int offset = -1 * visibleheight;         int distance = visibleheight + getlinecount() * lineheight;         int duration = (int) (distance * speed);           scroller.startscroll(0, offset, 0, distance, duration);     }        public void setspeed(float speed) {         this.speed = speed;     }      public float getspeed() {         return speed;     }      public void setcontinuousscrolling(boolean continuousscrolling) {         this.continuousscrolling = continuousscrolling;     }      public boolean iscontinuousscrolling() {         return continuousscrolling;     }  } 

mainactivity.java

public class mainactivity extends appcompatactivity{   @override protected void oncreate(bundle savedinstancestate) {     super.oncreate(savedinstancestate);     setcontentview(r.layout.activity_main);        }   } 

activity_main.xml

  <relativelayout 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:paddingbottom="@dimen/activity_vertical_margin"             android:paddingleft="@dimen/activity_horizontal_margin"             android:paddingright="@dimen/activity_horizontal_margin"             android:paddingtop="@dimen/activity_vertical_margin"             android:elevation="10dp"             tools:context=".mainactivity" >       <com.bhabani2077.scrolltext.autoscrollingtext         android:text="@string/random_text"         android:id="@+id/textview1"         android:focusable="true"         android:scrollhorizontally="false"         android:scrollbars="vertical"         android:ellipsize="marquee"         android:layout_width="match_parent"         android:marqueerepeatlimit ="marquee_forever"         android:layout_height="200dp"/>   </relativelayout>