I am displaying text in a textview that appears to be too long to fit into one screen. I need to make my TextView scrollable. How can I do that?
Here is the code:
final TextView tv = new TextView(this);
tv.setBackgroundResource(R.drawable.splash);
tv.setTypeface(face);
tv.setTextSize(18);
tv.setTextColor(R.color.BROWN);
tv.setGravity(Gravity.CENTER_VERTICAL| Gravity.CENTER_HORIZONTAL);
tv.setOnTouchListener(new OnTouchListener() {
public boolean onTouch(View v, MotionEvent e) {
Random r = new Random();
int i = r.nextInt(101);
if (e.getAction() == e.ACTION_DOWN) {
tv.setText(tips[i]);
tv.setBackgroundResource(R.drawable.inner);
}
return true;
}
});
setContentView(tv);
Make your textview just adding this
In my case.Constraint Layout.AS 2.3.
Code implementation:
XML:
whenever you need to use the ScrollView as parent, And you also use the scroll movement method with TextView.
And When you portrait to landscape your device that time occur some issue. (like) entire page is scrollable but scroll movement method can't work.
if you still need to use ScrollView as parent or scroll movement method then you also use below desc.
If you do not have any problems then you use EditText instead of TextView
see below :
Here, the EditText behaves like TextView
And your issue will be resolved
Use it like this
Put
maxLines
andscrollbars
inside TextView in xml.Then in java code.
textView.setMovementMethod(new ScrollingMovementMethod());
Add this to your XML layout:
And in code you have to write the following lines: