Android View.scrollTo(x, y) 滚动到哪里? [英] Where does Android View.scrollTo(x, y) scroll to?

查看:25
本文介绍了Android View.scrollTo(x, y) 滚动到哪里?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

scrollTo(int x, int y) 说:

x 要滚动到的 x 位置

x the x position to scroll to

y 要滚动到的 y 位置

y the y position to scroll to

<代码>onScrollChanged(int l, int t, int oldl, int oldt) 说:

l 当前水平滚动原点.

l Current horizontal scroll origin.

t 当前垂直滚动原点.

t Current vertical scroll origin.

我想知道但在任何地方都找不到的,是 x,y 在哪里?左上方?中心?我尝试了一些测试,但无法弄清楚.

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.

推荐答案

经过广泛的研究和测试,我终于明白了 scrollTo() 有效.

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

(0,0)查看 容器.当滚动到任何 (x,y) 点时,View 将被放置在 (x,y) 坐标处.

(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.

如果 View 显示图像,位图,比查看本身,滚动到 (0,0) 将放置 View 在图像的中心.这样,图像的左上角将位于 (-dX/2, -dY/2) 和右下角 (mW - dX/2, mH -dY/2).dX 表示图片宽度与查看.而 dY 表示图像高度与 查看.

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.

为了看到右下角而不是越过它(右下角或右下角),这是正确的调用:scrollTo(mW - ivW - dX/2, mH - ivH - dY/2);

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.

这篇关于Android View.scrollTo(x, y) 滚动到哪里?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆