本文控件為大家分享了Android隨手勢(shì)滑動(dòng)控件的具體代碼,供大家參考,具體內(nèi)容如下

1.新建自定義控件類:MyView
public class MyView extends Button{
//記錄上次滑動(dòng)后的坐標(biāo)值
private int lastX;
private int lastY;
public MyView(Context context) {
super(context);
// TODO Auto-generated constructor stub
}
public MyView(Context context, AttributeSet attrs){
super(context, attrs);
}
@Override
public boolean onTouchEvent(MotionEvent event) {
// 獲取view相對(duì)于手機(jī)屏幕的xy值
int x=(int) event.getRawX();
int y=(int) event.getRawY();
switch (event.getAction()) {
case MotionEvent.ACTION_DOWN:
break;
case MotionEvent.ACTION_MOVE:
int deltaX=x-lastX;
int deltaY=y-lastY;
int translationX = (int) (ViewHelper.getTranslationX(this) + deltaX);
int translationY = (int) (ViewHelper.getTranslationY(this) + deltaY);
ViewHelper.setTranslationX(this,translationX);
ViewHelper.setTranslationY(this,translationY);
break;
case MotionEvent.ACTION_UP:
break;
default:
break;
}
lastX = x;
lastY = y;
return true;
}
網(wǎng)站題目:Android自定義View實(shí)現(xiàn)隨手勢(shì)滑動(dòng)控件-創(chuàng)新互聯(lián)
本文來(lái)源:http://chinadenli.net/article40/dsjiho.html
成都網(wǎng)站建設(shè)公司_創(chuàng)新互聯(lián),為您提供網(wǎng)站建設(shè)、網(wǎng)站制作、網(wǎng)站排名、網(wǎng)站策劃、網(wǎng)站改版、自適應(yīng)網(wǎng)站
聲明:本網(wǎng)站發(fā)布的內(nèi)容(圖片、視頻和文字)以用戶投稿、用戶轉(zhuǎn)載內(nèi)容為主,如果涉及侵權(quán)請(qǐng)盡快告知,我們將會(huì)在第一時(shí)間刪除。文章觀點(diǎn)不代表本網(wǎng)站立場(chǎng),如需處理請(qǐng)聯(lián)系客服。電話:028-86922220;郵箱:631063699@qq.com。內(nèi)容未經(jīng)允許不得轉(zhuǎn)載,或轉(zhuǎn)載時(shí)需注明來(lái)源: 創(chuàng)新互聯(lián)
猜你還喜歡下面的內(nèi)容