3.0的ScrollView怎么mfc获取当前鼠标坐标坐标

下次自动登录
现在的位置:
& 综合 & 正文
ScrollView滚动到指定位置
滚到到指定位置:
final TextView titleTwo = (TextView) findViewById(R.id.title_two);
final boolean scrollDown = getIntent().getBooleanExtra(SCROLL_DOWN, false);
mRootScrollView = (ScrollView) findViewById(R.id.root);
if (scrollDown) {
mRootScrollView.post(new Runnable() {
public void run() {
//To change body of implemented methods use File | Settings | File Templates.
mRootScrollView.fullScroll(ScrollView.FOCUS_DOWN);
int[] location = new int[2];
titleTwo.getLocationOnScreen(location);
int offset = location[1] - mRootScrollView.getMeasuredHeight();
if (offset & 0) {
offset = 0;
mRootScrollView.smoothScrollTo(0, offset);
滚到到底部:
mRootScrollView.fullScroll(ScrollView.FOCUS_DOWN);
滚动到顶部:
mRootScrollView.fullScroll(ScrollView.FOCUS_UP);
注意需要post 一个runnable,让其在消息队列中执行滚动!
&&&&推荐文章:
【上篇】【下篇】16295人阅读
UIScrollView的判断位置的属性如下:
contentSize:CGSize类型,scrollview可以滑动的区域,例如,一个view的frame为(0,0,320,480),而scrollview的contentSize为(320,1080),则表示scrollView的垂直滑动区域为整个屏幕的3倍。
contentView:scrollview的内容显示区域,一般情况下和scrollview的contentsize保持一致。
contentOffset:CGPoint类型,它表示scrollView当前的显示区域顶点相对于frame顶点的偏移量,如在上面的例子中,如果某一时刻contentOffset的值为(0,960),就表示scrollview的偏移量为(0,960)。
contentInset:UIEdgeInsets类型,srollciew的contentView的顶点相对于scrollview的位置,它标识了contenView开始显示的位置,这个属性和css以及xaml中的margin属性类似。
知道了上面几个概念后,要判断srollciew是否滑到底部就容易多了,代码如下:
&&CGPoint&offset = scrollView.contentOffset;
CGRect&bounds = scrollView.bounds;
CGSize&size = scrollView.contentSize;
UIEdgeInsets&inset = scrollView.contentInset;
CGFloat&currentOffset = offset.y&+
bounds.size.height&–
inset.bottom;
CGFloat&maximumOffset = size.height;
当currentOffset与maximumOffset的值相等时,即说明scrollview已经滑到底部了。
同理,还可以根具上述两个偏移量的差值实现当滑到某一区域时,做点其它什么事,比如当滑到离底部还有50个像素的时候,在后台加载更多的数据:
&&if((maximumOffset – currentOffset)&50.0)
NSLog(@”LoadMore…”);
&&相关文章推荐
参考知识库
* 以上用户言论只代表其个人观点,不代表CSDN网站的观点或立场
访问:306096次
积分:2495
积分:2495
排名:第13546名
原创:48篇
评论:24条
(1)(1)(1)(1)(1)(1)(1)(4)(4)(5)(8)(16)(4)(3)(1)(1)

我要回帖

更多关于 js 获取鼠标当前坐标 的文章

 

随机推荐