android版instagramを真似てダブルクリックでいいね効果
1305 ワード
先に効果図を載せる
效果图gif
ダブルクリックの効果を実現し、いいねを押したアニメーションを表現します.
1ダブルクリック効果
Android sdkはGestureDetectoというクラスを提供してくれました.GestureDetectorというクラスは対外的に2つのインタフェースを提供しています.OnGestureListener、OnDoubleTapListener、そして内部クラスSimpleOnGestureListenerです.
インスタンス化GestureDetector
ビューのonTouchリスニングをキャプチャ
ダブルクリック操作でキャプチャしてアニメーション効果を開始します.ここでは簡単なScaleAnimationを使用します.
效果图gif
ダブルクリックの効果を実現し、いいねを押したアニメーションを表現します.
1ダブルクリック効果
Android sdkはGestureDetectoというクラスを提供してくれました.GestureDetectorというクラスは対外的に2つのインタフェースを提供しています.OnGestureListener、OnDoubleTapListener、そして内部クラスSimpleOnGestureListenerです.
public class OnDoubleClick extends GestureDetector.SimpleOnGestureListener {
@Override
public boolean onDoubleTap(MotionEvent e) {
//
return false;
}
public boolean onSingleTapConfirmed(MotionEvent e) {
//
return false;
}
}
インスタンス化GestureDetector
GestureDetector mGestureDetector = new GestureDetector(this, new OnDoubleClick());
ビューのonTouchリスニングをキャプチャ
view.setOnTouchListener(new OnTouchListener() {
@Override
public boolean onTouch(View view, MotionEvent event) {
return mGestureDetector.onTouchEvent(event);
}
});
ダブルクリック操作でキャプチャしてアニメーション効果を開始します.ここでは簡単な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);