Home » Android » java – TextView not scrolling Smoothly

java – TextView not scrolling Smoothly

Posted by: admin June 15, 2020 Leave a comment


I am trying to scroll my textview using the following code:

TextView text = (TextView) findViewById(R.id.textView12);
        int height = getResources().getDrawable(R.drawable.pic_ground_pranic).getIntrinsicHeight();
        text.setLayoutParams(new FrameLayout.LayoutParams(LayoutParams.FILL_PARENT, height));
        text.setText("As part of an Android App I am building a button set.For performance reasons and to keep the code simpler, the Android system uses pixels as the standard unit for expressing dimension or coordinate values. That means that the dimensions of a view are always expressed in the code using pixels, but always based on the current screen density. For instance, if myView.getWidth() returns 10, the view is 10 pixels wide on the current screen, but on a device with a higher density screen, the value returned might be 15. If you use pixel values in your application code to work with bitmaps that are not pre-scaled for the current screen density, you might need to scale the pixel values that you use in your code If you need to control exactly how your application will look on various screen configurations, adjust your layouts and bitmap drawables in configuration-specific resource directories. For example, consider an icon that you want to display on medium and high density screens. Simply create your icon at two different sizes (for instance 100x100 for medium density and 150x150 for high density) and put the two variations in the appropriate directories, using the proper qualifiers: For instance, suppose a device has a WVGA high-density screen, which is 480x800 and about the same size as a traditional HVGA screen, but it's running an application that has disabled pre-scaling. In this case, the system will lie to the application when it queries for screen dimensions, and report 320x533 (the approximate mdpi translation for the screen density). Then, when the application does drawing operations, such as invalidating the rectangle from (10,10) to (100, 100), the system transforms the coordinates by scaling them the appropriate amount, and actually invalidate the region (15,15) to (150, 150). This discrepancy may cause unexpected behavior if your application directly manipulates the scaled bitmap, but this is considered a reasonable trade-off to keep the performance of applications as good as possible. If you encounter this situation, read Based on the density of the current screen, the system uses any size- or density-specific resources from your application and displays them without scaling. If resources are not available in the correct density, the system loads the default resources and scales them up or down as needed to match the current screen's density. The system assumes that default resources (those from a directory without configuration qualifiers) are designed for the baseline screen density (mdpi), unless they are loaded from a density-specific resource directory. Pre-scaling is, thus, what the system does when resizing a bitmap to the appropriate size for the current screen density. to match the un-scaled bitmap source. The buttons are part of a nested set of LinearLayouts.The question then is: How to resize the layout.I have tried several suggested techniques, and none come close to working. Here is a subset of the XML that builds the button set:");

All is working fine but my text view is not scrolling smoothly. I thought I have to put my Textview inside a Scrollview but this is also not working.

Does it happen because I am resizing my textview?

Please provide any solution for this problem. I already spent a lot of time on this.

My xml layout file is:

Thanks in advance!

How to&Answers:

problem is ScrollView inside ScrollView.

When you put ScrollView inside ScrollView android just get confused which scroll view is touched. So sometimes it gets unable to deliver touch event.

After searching for a time I found a link or blog that will extract this problem and also have solution.

Take a look at this blog. This is exactly what you have been searching for and i am sure that it will solve your problem.

Now time to Enjoy 😉


In my case I just needed to put my TextView inside a ScrollView. Scrolling got very smooth and users lived happily every after!


The TextView scroll only if you restrict its height. Simple rule is when the text is more then the available space then textview start scrolling.
One way is what you are following by assigning a fixed height which you got from some image size. One other way is by setting the maximum number of lines.

you can even make it more dynamic. Simply by calculating number of lines.

Number of lines = (image Height in pixels)/(text font size in pixel)


First of all there is no need of the setting the Layoutparams as because you have give it in to the xml layout.

And if you have such long string then dont put it directly on java code. Instead of it put that string to the resources directory.

go to values, and open strings.xml file and define your string.

See below:

After doing that set the string in Java code whenever you want.
as like:

it Scroll nice as normal scrolling.

Hope it will help you.

Enjoy. 🙂