记录新的知识点: 1:为什么mContentFmLayout明明是FrameLayout 类型,在mContentFmLayout.getLayoutParams()得到的是LinearLayout, 看下源代码后发现,通过getLayoutParams()获取到的是父类的类型哦。
private FrameLayout mContentFmLayout; LinearLayout.LayoutParams lpC = (LinearLayout.LayoutParams) mContentFmLayout.getLayoutParams();2:设置头部下拉刷新成功后,头部隐藏的动画。
mHiddenAction = new SelfTranslateAnimation(0,0,0,-getResources().getDimensionPixelOffset(R.dimen.cheader_height)); mRootView.startAnimation(mHiddenAction);//执行动画 class SelfTranslateAnimation extends TranslateAnimation{ public SelfTranslateAnimation(float fromXDelta, float toXDelta, float fromYDelta, float toYDelta) { super(fromXDelta, toXDelta, fromYDelta, toYDelta); } @Override protected void applyTransformation(float interpolatedTime, Transformation t) {//这方法是关键哦,interpolatedTime是0到1的渐变。通过设置setDuration,控制渐变速度。 LinearLayout.LayoutParams llp = (LinearLayout.LayoutParams) mUpdateHeaderView.getLayoutParams(); llp.setMargins(0,-(int)(getResources().getDimensionPixelOffset(R.dimen.cheader_height)*interpolatedTime),0,0);//巧妙的通过设置负的margin来实现隐藏效果。 mUpdateHeaderView.setLayoutParams(llp); } }3.android事件分发注意事项: 1.首先事件先下发到父类如(ViewGroup),通过dispatchTouchEvent,若为true则阻止事件进一步下发,判断条件有两个onInterceptTouchEvent和disallowIntercept,两者的取值默认都为false,当disallowIntercept的值为true时事件就开始下发,或者当onInterceptTouchEvent为false时事件开始下发,disallowIntercept的另一个作用就是阻止将子控件的事件继续传到父类的ontouchevent中处理,当设置为true时就阻止了向父类继续传递。disallowIntercept的值可以通过调用requestDisallowInterceptTouchEvent方法对这个值进行修改,多用于滑动冲突解决如(竖直方向嵌套横向的scrollview的组合)。 2.在ontouchevent事件中若想事件向ACTION_MOVE传递,不能在down事件中就返回false,要返回true继续传递。
