简单拖动效果(带Cache,需要完善)
来源:互联网 发布:python zipline 编辑:程序博客网 时间:2024/06/17 22:09
如何去实现一个具有幻象的拖拽效果?
所谓”幻象“就是当你按下去拖动一个View时,View本身不动,拖动的是这个View的复制品,当抬起时真正的View才显示到拖动的地方。
复制品很容易解决,2句代码就可以了:
v.setDrawingCacheEnabled(true);
Bitmap bitmap = Bitmap.createBitmap(v.getDrawingCache());
Android Drag and Drop
http://www.vogella.com/tutorials/AndroidDragAndDrop/article.html
所谓”幻象“就是当你按下去拖动一个View时,View本身不动,拖动的是这个View的复制品,当抬起时真正的View才显示到拖动的地方。
复制品很容易解决,2句代码就可以了:
v.setDrawingCacheEnabled(true);
Bitmap bitmap = Bitmap.createBitmap(v.getDrawingCache());
package com.ql.app;import android.app.Activity;import android.os.Bundle;import android.util.Log;import android.view.MotionEvent;import android.view.View;import android.view.View.OnTouchListener;import android.widget.Button;import android.widget.FrameLayout;import android.widget.ImageView;import android.widget.FrameLayout.LayoutParams;/** * 参考:http://techdroid.kbeanie.com/2010/04/simple-drag-n-drop-on-android.html * @author admin * */public class App extends Activity implements OnTouchListener{private final static int START_DRAGGING = 0;private final static int STOP_DRAGGING = 1;private Button btn;private FrameLayout layout;private int status;private LayoutParams params;private ImageView image;/** Called when the activity is first created. */@Overridepublic void onCreate(Bundle savedInstanceState) {super.onCreate(savedInstanceState);setContentView(R.layout.main);layout = (FrameLayout) findViewById(R.id.layout);// layout.setOnTouchListener(this);btn = (Button) findViewById(R.id.btn);btn.setDrawingCacheEnabled(true);btn.setOnTouchListener(this);params = new LayoutParams(LayoutParams.WRAP_CONTENT,LayoutParams.WRAP_CONTENT);}@Overridepublic boolean onTouch(View view, MotionEvent me) {switch (me.getAction()) {case MotionEvent.ACTION_DOWN:status = START_DRAGGING;image = new ImageView(this);image.setImageBitmap(btn.getDrawingCache());layout.addView(image, params);break;case MotionEvent.ACTION_MOVE:if (status == START_DRAGGING) {image.setPadding((int) me.getRawX(), (int) me.getRawY(), 0, 0);image.invalidate();}break;case MotionEvent.ACTION_UP:status = STOP_DRAGGING;Log.i("Drag", "Stopped Dragging");//layout.removeView(image);break;default:break;}return false;}}
<?xml version="1.0" encoding="utf-8"?><FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"android:layout_width="fill_parent" android:layout_height="fill_parent"android:id="@+id/layout"><Button android:layout_width="wrap_content"android:layout_height="wrap_content" android:id="@+id/btn"android:text="Drag Me"/></FrameLayout>
Android Drag and Drop
http://www.vogella.com/tutorials/AndroidDragAndDrop/article.html
0 0
- 简单拖动效果(带Cache,需要完善)
- 简单拖动效果(带Cache,需要完善)
- 简单拖动效果
- jquery简单的拖动效果
- jquery简单的拖动效果
- js:简单的拖动效果
- 简单的鼠标拖动效果
- jquery简单的拖动效果
- 一个简单的行拖动效果
- 使用jquery实现简单的拖动效果
- Unity 简单的图标拖动效果
- LeetCode_LRU Cache(待完善)
- TabSwitcher自定义控件(带拖动&滑动效果)
- android实现按钮拖动效果及路径的绘制等2D绘图功能---待完善
- 拖动效果
- 拖动效果
- 拖动效果
- 拖动效果
- 可左右两侧挤压傍边布局的Android抽屉
- 使用ImageView应该注意的地方
- MySQL数据库——'授权语句'与'收回权限语句'
- Android中为图标加上数字--用于未读短信数提醒,待更新应用数提醒等
- 数据库
- 简单拖动效果(带Cache,需要完善)
- 无限级分类 增加
- ios中调用相册选择图片问题(继续更新中)
- Unity3D Shader 编辑器搭建
- 使用FrameLayout应该注意的地方
- 【ListView】相关文章
- 图片倒影控件ReflectionImage
- 多态
- Ubuntu 巧合