Android實(shí)現(xiàn)讓圖片在屏幕上任意移動(dòng)的方法(拖拽功能)
本文實(shí)例講述了Android實(shí)現(xiàn)讓圖片在屏幕上任意移動(dòng)的方法。分享給大家供大家參考,具體如下:
public class DragExampleActivity extends Activity {
Bitmap mBitmap;
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
mBitmap = BitmapFactory.decodeResource(getResources(), R.drawable.icon);
setContentView(new DragView(this));
}
@Override
protected void onDestroy()
{
super.onDestroy();
if(null != mBitmap) {
mBitmap.recycle();
mBitmap = null;
}
}
private class DragView extends View {
private int mMotionX = 0;
private int mMotionY = 0;
private Paint paint;
public DragView(Context context)
{
super(context);
paint = new Paint();
}
@Override
public void draw(Canvas canvas)
{
super.draw(canvas);
canvas.drawBitmap(mBitmap, mMotionX, mMotionY, paint);
}
@Override
public boolean onTouchEvent(MotionEvent ev)
{
if(ev.getAction() == MotionEvent.ACTION_DOWN)
{
mMotionX = (int) ev.getX();
mMotionY = (int) ev.getY();
invalidate();
return true;
}else {
return super.onTouchEvent(ev);
}
}
}
}
更多關(guān)于Android相關(guān)內(nèi)容感興趣的讀者可查看本站專題:《Android拍照與圖片處理技巧總結(jié)》、《Android編程之a(chǎn)ctivity操作技巧總結(jié)》、《Android視圖View技巧總結(jié)》、《Android操作SQLite數(shù)據(jù)庫技巧總結(jié)》、《Android操作json格式數(shù)據(jù)技巧總結(jié)》、《Android數(shù)據(jù)庫操作技巧總結(jié)》、《Android文件操作技巧匯總》、《Android編程開發(fā)之SD卡操作方法匯總》、《Android開發(fā)入門與進(jìn)階教程》、《Android資源操作技巧匯總》及《Android控件用法總結(jié)》
希望本文所述對大家Android程序設(shè)計(jì)有所幫助。
- android 大圖片拖拽并縮放實(shí)現(xiàn)原理
- Android使用RecycleView實(shí)現(xiàn)拖拽交換item位置
- Android自定義View實(shí)現(xiàn)可以拖拽的GridView
- Android DragVideo實(shí)現(xiàn)播放視頻時(shí)任意拖拽的方法
- Android中利用matrix 控制圖片的旋轉(zhuǎn)、縮放、移動(dòng)
- android 多點(diǎn)觸摸圖片縮放的具體實(shí)現(xiàn)方法
- Android 圖片縮放與旋轉(zhuǎn)的實(shí)現(xiàn)詳解
- Android開發(fā)之圖形圖像與動(dòng)畫(二)Animation實(shí)現(xiàn)圖像的漸變/縮放/位移/旋轉(zhuǎn)
- Android應(yīng)用中實(shí)現(xiàn)手勢控制圖片縮放的完全攻略
- Android自定義View實(shí)現(xiàn)可拖拽縮放的矩形框
相關(guān)文章
Android Studio 實(shí)現(xiàn)九宮格功能
這篇文章主要介紹了Android Studio 實(shí)現(xiàn)九宮格,本文通過實(shí)例代碼給大家介紹的非常詳細(xì),對大家的學(xué)習(xí)或工作具有一定的參考借鑒價(jià)值,需要的朋友可以參考下2020-04-04
Android viewpager在最后一頁滑動(dòng)之后跳轉(zhuǎn)到主頁面的實(shí)例代碼
這篇文章主要介紹了Android viewpager在最后一頁滑動(dòng)之后跳轉(zhuǎn)到主頁面的實(shí)例代碼的相關(guān)資料,需要的朋友可以參考下2016-08-08
Android文本輸入框(EditText)輸入密碼時(shí)顯示與隱藏
這篇文章主要介紹了Android文本輸入框(EditText)輸入密碼時(shí)顯示與隱藏的方法和示例,需要的朋友可以參考下2014-12-12
淺析Android手機(jī)衛(wèi)士關(guān)閉自動(dòng)更新
保存數(shù)據(jù)的四種方式,網(wǎng)絡(luò),廣播提供者,SharedPreferences,數(shù)據(jù)庫。接下來通過本文給大家介紹android手機(jī)衛(wèi)士關(guān)閉自動(dòng)更新的相關(guān)知識(shí),感興趣的朋友一起學(xué)習(xí)吧2016-04-04
Android 三種實(shí)現(xiàn)定時(shí)器詳解及實(shí)現(xiàn)方法
本文主要介紹 Android 定時(shí)器的知識(shí)資料,這里整理了三種方法來實(shí)現(xiàn)定時(shí)器的方法,有需要的小伙伴可以參考下2016-09-09
Android編程實(shí)現(xiàn)canvas繪制柱狀統(tǒng)計(jì)圖功能【自動(dòng)計(jì)算寬高及分度值、可左右滑動(dòng)】
這篇文章主要介紹了Android編程實(shí)現(xiàn)canvas繪制柱狀統(tǒng)計(jì)圖功能,具備自動(dòng)計(jì)算寬高及分度值及左右滑動(dòng)的功能,涉及Android canvas繪圖操作相關(guān)技巧,需要的朋友可以參考下2017-01-01
android仿Adapter實(shí)現(xiàn)自定義PagerAdapter方法示例
這篇文章主要給大家介紹了關(guān)于android仿Adapter實(shí)現(xiàn)自定義PagerAdapter的相關(guān)資料,文中詳細(xì)介紹了關(guān)于PagerAdapter的用法,對大家的理解和學(xué)習(xí)具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來一起學(xué)習(xí)學(xué)習(xí)吧。2017-11-11

