Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Where does Android View.scrollTo(x, y) scroll to?

scrollTo(int x, int y) says:

x the x position to scroll to

y the y position to scroll to

onScrollChanged(int l, int t, int oldl, int oldt) says:

l Current horizontal scroll origin.

t Current vertical scroll origin.

What I would like to know and can't find anywhere, is where is x,y? Top left? Center? I tried a few tests and can't figure it out.

like image 923
slybloty Avatar asked Oct 14 '11 20:10

slybloty


People also ask

How can I tell if ScrollView is scrolling Android?

Do you know if it is possible to know if an Android Widget ScrollView can scroll? If it has enough space it doesn't need to scroll, but as soon as a dimension exceeds a maximum value the widget can scroll.

How can I make my Android scroll faster?

So if you'd like to adjust these, tap the three-dot menu button at the top of the screen, then head to the "Settings" entry. From here, the "Speed of scrolling" option lets you adjust how fast the automatic scrolling will be.


1 Answers

After extensive research and testing I've finally understood how scrollTo() works.

(0,0) are the coordinates to the top left corner of the View container. When scrolling to any (x,y) point, the top left corner of the View will be placed at the (x,y) coordinates.

If the View is showing an image, Bitmap, larger than the View itself, scrolling to (0,0) will place the View in the center of the image. This way, the top left corner of the image will be located at (-dX/2, -dY/2) and the bottom right corner at (mW - dX/2, mH - dY/2). dX represents the difference between the widths of the image and the View. And dY represents the difference between the heights of the image and the View.

In order to see the bottom right corner and not go passed it (lower or further to the right), this is the proper call: scrollTo(mW - ivW - dX/2, mH - ivH - dY/2);

The attached image shows the graphical representation of the View and Bitmap image positioning.

Graphical representation of the relationship between the image and the view.

like image 185
slybloty Avatar answered Sep 23 '22 11:09

slybloty