<com.lin.gesturedetector.MyViewGroup android:id="@+id/view_group" android:layout_width="match_parent" android:layout_height="match_parent"> <include android:id="@+id/group_top" layout="@layout/view_top" /> <include android:id="@+id/group_bottom" layout="@layout/view_bottom" /> </com.lin.gesturedetector.MyViewGroup>
@Override
public boolean onScroll(MotionEvent e1, MotionEvent e2, float distanceX, float distanceY) {
Log.i(tag, "onScroll -> distanceY" + distanceY);
if (distanceY < 0) {// 手势向下滑动是负值
animatorLayoutOffset(1);
}
if (distanceY > 0) {
animatorLayoutOffset(0f);
}
return true;
}
@Override
protected void onFinishInflate() {
super.onFinishInflate();
viewTop = findViewById(R.id.group_top);
viewBottom = findViewById(R.id.group_bottom);
}
@Override
protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
int width = MeasureSpec.getSize(widthMeasureSpec);
int height = MeasureSpec.getSize(heightMeasureSpec);
viewTop.measure(MeasureSpec.makeMeasureSpec(width, MeasureSpec.EXACTLY), MeasureSpec.makeMeasureSpec(height, MeasureSpec.AT_MOST));
viewBottom.measure(MeasureSpec.makeMeasureSpec(width, MeasureSpec.EXACTLY), MeasureSpec.makeMeasureSpec(height, MeasureSpec.EXACTLY));
setMeasuredDimension(width, height);
}
@Override
protected void onLayout(boolean changed, int l, int t, int r, int b) {
int topHeight = viewTop.getMeasuredHeight();
float offset = layoutOffset * topHeight;
int width = r - l;
float topViewYTop = offset - topHeight;
float topViewYBottom = topViewYTop + topHeight;
viewTop.layout(0, (int) topViewYTop, width, (int) topViewYBottom);
viewBottom.layout(0, (int) topViewYBottom, width, (int) topViewYBottom + viewBottom.getMeasuredHeight());
}
private void animatorLayoutOffset(float offset) {
if (animator != null && animator.isRunning()) {
return;
}
animator = ObjectAnimator.ofFloat(this, "layoutOffset", layoutOffset, offset);
animator.setDuration(500);
animator.start();
}
机械节能产品生产企业官网模板...
大气智能家居家具装修装饰类企业通用网站模板...
礼品公司网站模板
宽屏简约大气婚纱摄影影楼模板...
蓝白WAP手机综合医院类整站源码(独立后台)...苏ICP备2024110244号-2 苏公网安备32050702011978号 增值电信业务经营许可证编号:苏B2-20251499 | Copyright 2018 - 2025 源码网商城 (www.ymwmall.com) 版权所有