先上效果圖
效果圖.gif
實(shí)現(xiàn)雙擊的效果,然后將點(diǎn)贊的動(dòng)畫體現(xiàn)出來。
1 雙擊效果
Android sdk給我們提供了GestureDetecto這個(gè)類,GestureDetector這個(gè)類對(duì)外提供了兩個(gè)接口:OnGestureListener,OnDoubleTapListener,還有一個(gè)內(nèi)部類SimpleOnGestureListener。
public class OnDoubleClick extends GestureDetector.SimpleOnGestureListener {
@Override
public boolean onDoubleTap(MotionEvent e) {
//雙擊
return false;
}
public boolean onSingleTapConfirmed(MotionEvent e) {
//單擊
return false;
}
}
實(shí)例化GestureDetector
GestureDetector mGestureDetector = new GestureDetector(this, new OnDoubleClick());
將view的onTouch監(jiān)聽捕捉到
view.setOnTouchListener(new OnTouchListener() {
@Override
public boolean onTouch(View view, MotionEvent event) {
return mGestureDetector.onTouchEvent(event);
}
});
雙擊操作捕捉到后就開始動(dòng)畫效果,這里用簡(jiǎn)單的ScaleAnimation
ScaleAnimation animation_ScaleAnimation = new ScaleAnimation(1.0f, 1.5f, 1.0f, 1.5f,
Animation.RELATIVE_TO_SELF, 0.5f, Animation.RELATIVE_TO_SELF, 0.5f);
animation_ScaleAnimation.setDuration(600);