Android随手指移动的DragView(二)——移动DragView
来源:互联网 发布:索尼网络经销商 编辑:程序博客网 时间:2024/06/05 04:18
获取偏移量offsetX和offsetY后,可以通过以下几种方式移动DragView:
(1),通过layout实现DragView的移动。
layout(getLeft() + offsetX, getTop() + offsetY, getRight() + offsetX, getBottom() + offsetY);
(2),通过ViewGroup.MarginLayoutParams实现DragView的移动。
ViewGroup.MarginLayoutParams mlp = (ViewGroup.MarginLayoutParams) getLayoutParams(); mlp.leftMargin = getLeft() + offsetX; mlp.topMargin = getTop() + offsetY; setLayoutParams(mlp);
(3),通过offsetLeftAndRight和offsetTopAndBottom实现DragView的移动。
//View封装好的方法,调用即可offsetLeftAndRight(offsetX);offsetTopAndBottom(offsetY);
(4),通过scrollTo实现DragView的移动。
//注意这里移动的是父布局,所以需要调用parent.getScrollX()//而且getLeft一直不变,因为子View一直没动,改变的是父布局而已 View parent = (View) getParent(); parent.scrollTo(parent.getScrollX() - offsetX, parent.getScrollY() - offsetY);
(5),通过scrollBy实现DragView的移动。
//因为移动的父View,父View像左移动,子View相对向右移动。所以为-offsetX。((View) getParent()).scrollBy(-offsetX, -offsetY);
0 0
- Android随手指移动的DragView(二)——移动DragView
- Android随手指移动的DragView(一)——获取偏移量
- DragView(二)
- Android 自定义View--DragView
- Android 自定义View基础(五)--DragView
- android:View随手指的移动而移动
- android 随手指移动划线
- Android 随手指移动小球
- UIView随手指的移动
- DragView(一)
- [Android算法] Android 随手指移动的ImageView
- Android onTouchEvent 随手指移动时的抖动
- android中view随手指移动
- Android——自定义View随手自由移动
- 圆形随手指移动
- dragView一些知识 -未完成状态
- Android从基础做起——自定义View(随手移动的小球)
- ios的视图随手指移动
- 恭喜自己,继续努力
- Android Studio调用百度语音识别API
- css 层级 脱标流 可见性
- Spring 依赖注入(DI)
- .properties 文件
- Android随手指移动的DragView(二)——移动DragView
- 写在探索源码的路上
- jQ模拟打字效果插件typetype
- Android屏幕适配全攻略(最权威的官方适配指导)
- css 容易混淆属性
- 继承设计的一些小技巧
- java虚拟机——对象的布局、访问方式
- Python3爬虫学习笔记2.2——爬图片-妹子图
- php学习之数据类型