上下面板切换效果(类似大黑板效果)
来源:互联网 发布:目标跟踪算法速度对比 编辑:程序博客网 时间:2024/05/22 04:26
上篇blog介绍了ViewDragHelper的简单的使用,这篇blog再用ViewDragHelper来实现一个效果,先上图
再上代码:
public class BlackboardView extends ViewGroup { private int mWidth;//控件的宽 private int mHeight;//控件的高 private View topView, bottonView, capturedView; private ViewDragHelper mHelper; private ViewDragHelper.Callback callback = new ViewDragHelper.Callback() { @Override public boolean tryCaptureView(View child, int pointerId) { return (topView == child) || (bottonView == child); } @Override public int clampViewPositionVertical(View child, int top, int dy) { if (top < 0) return 0; if (top > mHeight / 2) return mHeight / 2; return top; } @Override public int clampViewPositionHorizontal(View child, int left, int dx) { return 0; } @Override public void onViewReleased(View releasedChild, float xvel, float yvel) { super.onViewReleased(releasedChild, xvel, yvel); if (releasedChild.getTop() < mHeight / 4) mHelper.smoothSlideViewTo(releasedChild, 0, 0); else mHelper.smoothSlideViewTo(releasedChild, 0, mHeight / 2); ViewCompat.postInvalidateOnAnimation(BlackboardView.this); } @Override public void onViewCaptured(View capturedChild, int activePointerId) { super.onViewCaptured(capturedChild, activePointerId); capturedView = capturedChild; } @Override public void onViewPositionChanged(View changedView, int left, int top, int dx, int dy) { super.onViewPositionChanged(changedView, left, top, dx, dy); if (changedView == capturedView) { if (changedView == topView) bottonView.offsetTopAndBottom(-dy); else if (changedView == bottonView) topView.offsetTopAndBottom(-dy); } } }; public BlackboardView(Context context, AttributeSet attrs) { super(context, attrs); init(); } public BlackboardView(Context context) { super(context); init(); } public BlackboardView(Context context, AttributeSet attrs, int defStyleAttr) { super(context, attrs, defStyleAttr); init(); } private void init() { mHelper = ViewDragHelper.create(this, callback); } @Override protected void onSizeChanged(int w, int h, int oldw, int oldh) { super.onSizeChanged(w, h, oldw, oldh); mWidth = getMeasuredWidth(); mHeight = getMeasuredHeight(); } @Override protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) { super.onMeasure(widthMeasureSpec, heightMeasureSpec); for (int i = 0; i < getChildCount(); i++) { measureChild(getChildAt(i), widthMeasureSpec, heightMeasureSpec); } } @Override protected void onLayout(boolean changed, int l, int t, int r, int b) { topView = getChildAt(0); bottonView = getChildAt(1); topView.layout(0, 0, mWidth, mHeight / 2); bottonView.layout(0, mHeight / 2, mWidth, mHeight); } @Override public boolean onInterceptTouchEvent(MotionEvent ev) { return mHelper.shouldInterceptTouchEvent(ev); } @Override public boolean onTouchEvent(MotionEvent event) { mHelper.processTouchEvent(event); return true; } @Override public void computeScroll() { super.computeScroll(); if (mHelper.continueSettling(true)) { ViewCompat.postInvalidateOnAnimation(this); } }
代码不难,比起上一篇blog,只是callback多2个回调函数,以及控制了两个子view的滑动。
public void onViewCaptured(View capturedChild, int activePointerId)
当滑动某一个子view时回调,down-move-up过程中只回调一次
public void onViewPositionChanged(View changedView, int left, int top, int dx, int dy)
当子view位置变化时调用,不一定是拖动的那个。
0 0
- 上下面板切换效果(类似大黑板效果)
- qq面板切换效果
- 类似 qq 切换效果
- Flex滑动面板,类似QQ隐藏效果
- QQ面板切换效果(web版)【实例】
- jQuery底部带导航的图片切换,定时上下滚动效果(无滚轮切换效果)
- jquery插件实现面板切换效果
- 动态面板制作tab切换效果
- 带箭头的图片上下切换效果
- js模拟QQ面板拖拽效果及状态切换效果(DOM事件)
- js简单实现类似图片切换效果
- 面板移动效果(sates)
- [IOS]视图切换 JASidePanels (类似path2.0或者facebook系统设置,切换效果 )
- 视频直播时做多场景切换(实现类似切换台的效果)
- js jquery 写 面板 跳转 切换 有动画效果
- Axure使用动态面板制作tab切换效果
- Axure的动态面板制作tab切换效果
- 个人页效果(上下滚动时菜单悬停且可左右切换)
- CodeForces 159D Palindrome pairs(manacher)
- Android 4.4 上实现透明导航栏和状态栏 Translucent system bar
- hdu1166 2011.2.17
- usaco palsquare
- 获得数据库连接池中数据连接资源的两种方式
- 上下面板切换效果(类似大黑板效果)
- usaco pprime
- orcal 游标查询数据形式输出到控制台
- usaco rect1
- usaco sprime
- HTML <!DOCTYPE> 标签
- couchbase
- usaco transform
- ural 1005 2011.2.25