DragView(一)
来源:互联网 发布:数据库中索引是什么 编辑:程序博客网 时间:2024/05/17 23:35
传承者(Inheritors)打造共同进步生态圈!!!
转载:
http://blog.csdn.net/lmj623565791/article/details/46858663;
三段论:
思考,自定义,使用
public class CustomViewGroup2 extends LinearLayout { private ViewDragHelper mViewDragHelper; public CustomViewGroup2(Context context) { this(context,null); } public CustomViewGroup2(Context context, AttributeSet attrs) { super(context, attrs); mViewDragHelper = ViewDragHelper.create(this, 1.0f, new ViewDragHelper.Callback() { @Override public boolean tryCaptureView(View child, int pointerId) { return true; } @Override public int clampViewPositionHorizontal(View child, int left, int dx) { final int leftBound = getPaddingLeft(); final int rightBound = getWidth()-child.getWidth()-leftBound; final int mewLeft = Math.min(Math.max(left,leftBound),rightBound); return mewLeft; } @Override public int clampViewPositionVertical(View child, int top, int dy) { return top; } }); } @Override public boolean onInterceptTouchEvent(MotionEvent ev) { return mViewDragHelper.shouldInterceptTouchEvent(ev); } @Override public boolean onTouchEvent(MotionEvent event) { mViewDragHelper.processTouchEvent(event); return true; }}
调用
<?xml version="1.0" encoding="utf-8"?><com.example.administrator.testapplication.CustomViewGroup2 xmlns:android="http://schemas.android.com/apk/res/android" android:orientation="vertical" android:layout_width="match_parent" android:layout_height="match_parent"> <TextView android:layout_margin="10dp" android:gravity="center" android:layout_gravity="center" android:background="#44ff0000" android:text="I can be dragged !" android:layout_width="100dp" android:layout_height="100dp"/> <TextView android:layout_margin="10dp" android:layout_gravity="center" android:gravity="center" android:background="#44ff0000" android:text="I can be dragged !" android:layout_width="100dp" android:layout_height="100dp"/> <TextView android:layout_margin="10dp" android:layout_gravity="center" android:gravity="center" android:background="#44ff0000" android:text="I can be dragged !" android:layout_width="100dp" android:layout_height="100dp"/></com.example.administrator.testapplication.CustomViewGroup2>
部分方法解释
/** * Restrict the motion of the dragged child view along the horizontal axis. * The default implementation does not allow horizontal motion; the extending * class must override this method and provide the desired clamping. * * * @param child Child view being dragged * @param left Attempted motion along the X axis * @param dx Proposed change in position for left * @return The new clamped position for left */ public int clampViewPositionHorizontal(View child, int left, int dx) { return 0; } /** * Restrict the motion of the dragged child view along the vertical axis. * The default implementation does not allow vertical motion; the extending * class must override this method and provide the desired clamping. * * * @param child Child view being dragged * @param top Attempted motion along the Y axis * @param dy Proposed change in position for top * @return The new clamped position for top */ public int clampViewPositionVertical(View child, int top, int dy) { return 0; }
效果:
0 0
- DragView(一)
- DragView(二)
- Android随手指移动的DragView(一)——获取偏移量
- Android 自定义View--DragView
- dragView一些知识 -未完成状态
- Android 自定义View基础(五)--DragView
- Android随手指移动的DragView(二)——移动DragView
- dragView 可以在屏幕拖拽并且弹出菜单的控件
- (一)
- (一)
- (一)
- (一)
- (一)
- hibernate一二级缓存(一)
- 每日一题(一)
- 一、对象导论(一)
- 万能的一玄:一玄创业故事(一)
- python(一)端口扫描器(一)
- 最全的静态网站生成器(开源项目)
- oracle表空间操作
- 在myeclipse中基于Hibernate框架开发的入门小程序
- 调整python默认递归深度
- 工作窃取算法
- DragView(一)
- 开放的智力
- Gprof性能分析工具
- plugin sdk updater was not loaded
- java中的原子操作类
- 关于HTTP
- 全面理解面向对象的 JavaScript
- php保留两位小数,四舍五入与否
- java线程中几种方法的对比