[Android算法] Android 随手指移动的ImageView
来源:互联网 发布:国内的人工智能龙头股 编辑:程序博客网 时间:2024/05/22 08:26
主要是基于Android的随手指移动的ImageView,附有图片和源代码,希望会对大家有所帮助。
效果:
首次进入程序,手指点击屏幕上的任意位置,图片会随之移动。
布局文件
<?xml version="1.0" encoding="utf-8"?>
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/FrameLayout01"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="#f0f0f0" >
<com.sgw.move.MoveImageView
android:id="@+id/ImageView01"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="@drawable/icon" >
</com.sgw.move.MoveImageView>
</FrameLayout>
实现代码
public class MoveImageView extends ImageView {
public MoveImageView(Context context) {
super(context);
}
public MoveImageView(Context context, AttributeSet attrs) {
super(context, attrs, 0);
}
public MoveImageView(Context context, AttributeSet attrs, int defStyle) {
super(context, attrs, defStyle);
}
public void setLocation(int x, int y) {
this.setFrame(x, y - this.getHeight(), x + this.getWidth(), y);
}
// 移动
public boolean autoMouse(MotionEvent event) {
boolean rb = false;
switch (event.getAction()) {
case MotionEvent.ACTION_MOVE:
this.setLocation((int) event.getX(), (int) event.getY());
rb = true;
break;
}
return rb;
}
}
public class TestImageViewMove extends Activity {
private MoveImageView moveImageView;
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
moveImageView = (MoveImageView) this.findViewById(R.id.ImageView01);
}
@Override
public boolean onTouchEvent(MotionEvent event) {
moveImageView.autoMouse(event);
return false;
}
}
- [Android算法] Android 随手指移动的ImageView
- android 随手指移动划线
- Android 随手指移动小球
- android:View随手指的移动而移动
- 【Android】可移动的ImageView
- Android onTouchEvent 随手指移动时的抖动
- android中view随手指移动
- 一个随手指移动的自定义View和一个随手指移动的ImageView(附源码)
- Android随手指移动的DragView(二)——移动DragView
- Android 移动缩放的ImageView
- Android自实现activity之间切换,view随手指移动
- 每日一结:Android View随手指移动 CoordinatorLayout
- Android 开源项目浅读-------SwipeMenuListView-重写,第三章,随手指移动的菜单
- Android随手指移动的DragView(一)——获取偏移量
- android 利用ViewDragHelper实现childView可随手指移动的自定义ViewGroup
- UIView随手指的移动
- Android:手把手教你打造可缩放移动的ImageView
- ios的视图随手指移动
- oracle行列转换、多行转字符串等总结
- 简易的ATM机
- Dalvik jit分析
- linux0.11是如何加载并执行一个二进制可执行文件和shell脚本文件的?
- POJ 3037 Skiing
- [Android算法] Android 随手指移动的ImageView
- python中获取目录下的文件数
- Linux 卸载
- windows编码约定
- Gamma函数
- poj 1035
- IOS自动化打包介绍
- jquery中的可见性过滤选择器
- Android 高手进阶教程(十四)之----Android Location的使用!!