The Horizontal ScrollView of a TextView slide automatically when inserting dynamic text

6

I have a simple layout as shown below that has a ScrollView horizontal when it exceeds the limit of TextView .

But I would like when inserting text the focus of TextView always stays in the last value entered and does not have to scroll the bar to see the last value inserted.

Type an automatic scroll to follow the entered values.

And go back with the bar manually to start if you need to.

Does anyone have any idea how to do it?

Activity :

public class MainActivity extends AppCompatActivity {
  @Override
   protected void onCreate(Bundle savedInstanceState) {
     super.onCreate(savedInstanceState);
     setContentView(R.layout.activity_main);       
     textview = (TextView) findViewById(R.id.textview);
     textview.setMovementMethod(new ScrollingMovementMethod());
   }
}

xml :          

    <HorizontalScrollView
      android:id="@+id/horizontalScrollView"
      android:layout_width="wrap_content"
      android:layout_height="wrap_content"
      android:layout_gravity="right">

      <TextView
           android:id="@+id/display0"
           android:layout_width="wrap_content"
           android:layout_height="wrap_content"
           android:editable="false"
           android:gravity="center|right" />
      </HorizontalScrollView>
</LinearLayout>
    
asked by anonymous 06.01.2016 / 22:15

1 answer

2

Try to do this:

ScrollView sc = ((ScrollView) R.findViewById(R.id.scroll);

sc.post(new Runnable() { 
    public void run() { 
        sc.fullScroll(ScrollView.FOCUS_DOWN); 
    } 
}); 
    
10.03.2016 / 18:26