CoordinatorLayout学习笔记

记录协同布局学习之路
嵌套滑动布局CoordinatorLayout,这篇文章讲得特别好,我看了那么多文章后,觉得这篇文章看完有一种豁然开朗的感觉。文档地址:https://blog.csdn.net/briblue/article/details/73076458


 

以下是官方文档中有关嵌套滑动主要方法说明:

onStartNestedScroll方法:该方法的返回值决定是否执行嵌套滑动
onNestedPreScroll方法:处理具体的滑动
CoordinatorLayout类实现了NestedScrollingParent2接口

    
RecyclerView类实现了NestedScrollingChild2和NestedScrollingChild3接口


public interface NestedScrollingChild {

    public boolean dispatchNestedFling(float velocityX, float velocityY, boolean consumed);

    public boolean dispatchNestedPreFling(float velocityX, float velocityY);

    public boolean dispatchNestedPreScroll(int dx, int dy, int[] consumed, int[] offsetInWindow);

    public boolean dispatchNestedScroll(int dxConsumed, int dyConsumed, int dxUnconsumed, int dyUnconsumed, int[] offsetInWindow);

    public boolean hasNestedScrollingParent();

    public boolean isNestedScrollingEnabled();

    public void setNestedScrollingEnabled(boolean enabled);

    public boolean startNestedScroll(int axes);

    public void stopNestedScroll();

NestedScrollingParent接口
public interface NestedScrollingParent {

    public int getNestedScrollAxes();

    public boolean onNestedFling(View target, float velocityX, float velocityY, boolean consumed);

    public boolean onNestedPreFling(View target, float velocityX, float velocityY);

    public void onNestedPreScroll(View target, int dx, int dy, int[] consumed);

    public void onNestedScroll(View target, int dxConsumed, int dyConsumed,int dxUnconsumed, int dyUnconsumed);

    public void onNestedScrollAccepted(View child, View target, int nestedScrollAxes);

    public boolean onStartNestedScroll(View child, View target, int nestedScrollAxes);

    public void onStopNestedScroll(View target);

View类

public final int getLeft(){

     return mLeft;

}
getLeft方法获取的是mLeft,也就是:从View父控件的左边距到View控件的左边距的距离(以像素为单位)

public final int getRight(){

    return mRight;

}

mRight的含义是:View父控件的左边距到View控件的右边距的距离(以像素为单位)

所以控件宽度=mRight-mLeft

public final int getWidth(){

      return mRight-mLeft;

}

public float getX() {

     return mLeft + getTranslationX();

}

getX()获取的是mLeft+getTranslationX(),视图的可视位置,像素为单位。
getTranslationX()获取的是View的水平移动距离,水平移动向右移动值为正,垂直移动向下移动值为正,属性动画ObjectAnimator valueAnimator2 = ObjectAnimator.ofFloat(txtTitle, "translationY", -20);//  

public float getTranslationX()   含义:获取View相对与自身mLeft的水平位置(以像素为单位,相对位置)。

public void setTranslationX(float translationX)  含义:设置View相对于自身mLeft的水平位置(以像素为单位,相对位置)。

 public void setX(float x) {
        setTranslationX(x - mLeft);
    }

getTranslationX和getTranslationY移动的是View本身 水平向右值为负,水平向左值为正,垂直向下值为负,垂直向上值为正数。
滑动的方法scrollTo和scrollBy方法移动的不是View本身,是View的内容。

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值