scrollBy scrollTo使用方法
来源:互联网 发布:sd数据恢复免费软件 编辑:程序博客网 时间:2024/06/07 07:07
在View.java中
/** * The offset, in pixels, by which the content of this view is scrolled * horizontally.该视图相对于起始位置的X轴偏移量 * {@hide} */ @ViewDebug.ExportedProperty(category = "scrolling") protected int mScrollX; /** * The offset, in pixels, by which the content of this view is scrolled * vertically.该视图相对于起始位置的Y轴偏移量 * {@hide} */ @ViewDebug.ExportedProperty(category = "scrolling") protected int mScrollY;
/** * Return the scrolled left position of this view. This is the left edge of * the displayed part of your view. You do not need to draw any pixels * farther left, since those are outside of the frame of your view on * screen. * * @return The left edge of the displayed part of your view, in pixels. */ public final int getScrollX() { return mScrollX; } /** * Return the scrolled top position of this view. This is the top edge of * the displayed part of your view. You do not need to draw any pixels above * it, since those are outside of the frame of your view on screen. * * @return The top edge of the displayed part of your view, in pixels. */ public final int getScrollY() { return mScrollY; }
/** * Set the scrolled position of your view. This will cause a call to * {@link #onScrollChanged(int, int, int, int)} and the view will be * invalidated. 当前内容偏移至(x, y)位置 * @param x the x position to scroll to * @param y the y position to scroll to */ public void scrollTo(int x, int y) { //偏移位置发生了变化 if (mScrollX != x || mScrollY != y) { int oldX = mScrollX; int oldY = mScrollY; mScrollX = x; mScrollY = y; invalidateParentCaches(); onScrollChanged(mScrollX, mScrollY, oldX, oldY); if (!awakenScrollBars()) { invalidate(true); } } } /** * Move the scrolled position of your view. This will cause a call to * {@link #onScrollChanged(int, int, int, int)} and the view will be * invalidated. 当前内容偏移(x, y)个单位 * @param x the amount of pixels to scroll by horizontally * @param y the amount of pixels to scroll by vertically */ public void scrollBy(int x, int y) { scrollTo(mScrollX + x, mScrollY + y); }
例如:
1.
初始布局如下,绿色为LinearLayout,,橘色为TextView,左上为(0,0)点
当调用LinearLayout.scrollTo(100,0)时,相当于滚动条X方向移动到100位置,Y方向不移动,实质LinearLayout中的内容即TextView向左移动,效果如下
2. LinearLayout.scrollBy(100,0)实质也是调用的scrollTo
- scrollBy scrollTo使用方法
- ScrollBy & ScrollTo
- scrollTo vs scrollBy
- scrollTo 与 scrollBy
- 总结Scroller ScrollTo ScrollBy
- scrollTo、scrollBy、getScrollX、getScrollY
- Android View scrollTo scrollBy
- android scrollto scrollby 扯一扯
- ScrollTo 和ScrollBy学习
- scrollTo与scrollBy
- scrollTo和scrollBy
- scrollto与scrollby
- 【Android】【滑屏】scrollTo,scrollBy
- scrollTo与scrollBy
- ScrollTo,scrollBy,getScrollX()
- scrollTo与scrollBy
- scrollTo,scrollBy,smoothScrollBy,smoothScrollTo
- 理解scrollBy 与 scrollTo
- android Android.mk详细讲解
- 『颜色空间』记录
- 十条不错的编程观点
- HDU 2016 数据的交换输出
- TestComplete9下载安装
- scrollBy scrollTo使用方法
- JOGL
- 使用Visual Leak Detector检测内存…
- boost 智能指针
- 哈佛大学图书馆的20条经典训…
- SQLite语法和操作演示
- JavaScript 调用 C++
- JAVA中SERIALVERSIONUID
- WebBrowser介绍——Javascript与C++…