Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Making TextView scrollable on Android

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); 
like image 464
Muhammad Maqsoodur Rehman Avatar asked Nov 17 '09 13:11

Muhammad Maqsoodur Rehman


People also ask

How do I enable scrolling in TextView?

To make TextView scrollable, you don't need to use ScrollView, just add android:scrollbars=”vertical” attribute in TextView and then add two line of code in your java activity file. Following is the xml layout file which contain a LinearLayout and a TextView.

How do I make text scrollable?

You can create scrolling text in HTML using the <marquee> tag, or you can create CSS scrolling text (the preferred method). You can make your text scroll from right to left. You can make it scroll left to right.

How do I make my android activity scrollable?

You can make your activity scrollable using ScrollView. Its very simple and effective to use. Just copy code of ScrollView from below and paste it in your layout xml file. You can use this ScrollView with Linear as well as Relative Layout also.

How do you make text scrollable on flutter?

We can make the text scrollable in flutter using these 2 widgets: Expanded Class: A widget that expands a child of a Row, Column, or Flex so that the child fills the available space. SingleChildScrollView Class: A box in which a single widget can be scrolled.


1 Answers

You don't need to use a ScrollView actually.

Just set the

android:scrollbars = "vertical" 

properties of your TextView in your layout's xml file.

Then use:

yourTextView.setMovementMethod(new ScrollingMovementMethod());

in your code.

Bingo, it scrolls!

like image 57
Amit Chintawar Avatar answered Sep 20 '22 03:09

Amit Chintawar