android-view讲解 - 随心

       
       /**
	 * The offset, in pixels, by which the content of this view is scrolled
	 * horizontally.
	 * {@hide}
	 */
	protected int mScrollX;   //该视图内容相当于视图起始坐标的偏移量   , X轴 方向
	/**
	 * The offset, in pixels, by which the content of this view is scrolled
	 * vertically.
	 * {@hide}
	 */
	protected int mScrollY;   //该视图内容相当于视图起始坐标的偏移量   , Y轴方向

	/**
     * 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;
    }
/**
 * public void scrollTo(int x, int y)
 * 说明:在当前视图内容偏移至(x , y)坐标处,即显示(可视)区域位于(x , y)坐标处。
 * 方法原型为: View.java类中 
 * 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. 
 * @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;  
        //回调onScrollChanged方法  
        onScrollChanged(mScrollX, mScrollY, oldX, oldY);  
        if (!awakenScrollBars()) {  
            invalidate();  //一般都引起重绘  
        }  
    }  
} 
 
/** 
   * public void scrollBy(int x, int y)    
   * 说明:在当前视图内容继续偏移(x , y)个单位,显示(可视)区域也跟着偏移(x,y)个单位。即有叠加的效果
   * 方法原型为: View.java类中
   * 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. 
   * @param x the amount of pixels to scroll by horizontally 
   * @param y the amount of pixels to scroll by vertically 
   */  
  // 看出原因了吧 。。 mScrollX 与 mScrollY 代表我们当前偏移的位置 , 在当前位置继续偏移(x ,y)个单位  
  public void scrollBy(int x, int y) {  
      scrollTo(mScrollX + x, mScrollY + y);  
  }  

invalidate()可以再次触发一次onDraw事件
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值