In my view, recycler layout for gallery app.
I want to enable the pinch touch event listener so that the column type is recycler no. increases or decreases by pich in and out.
I have seen this type of interface in many gallery applications.
What is the best way to achieve this so that the transition is smooth.
A small link to the video: - http://sendvid.com/s68fiqpd
I tried using the code below (as pointed out by @Yogesh Rathi), but the results are not what I want to achieve.
import android.content.Context; import android.graphics.Canvas; import android.support.annotation.NonNull; import android.support.v7.widget.RecyclerView; import android.util.AttributeSet; import android.view.MotionEvent; import android.view.ScaleGestureDetector; public class PinchRecyclerView extends RecyclerView { private static final int INVALID_POINTER_ID = -1; private int mActivePointerId = INVALID_POINTER_ID; private ScaleGestureDetector mScaleDetector; private float mScaleFactor = 1.f; private float maxWidth = 0.0f; private float maxHeight = 0.0f; private float mLastTouchX; private float mLastTouchY; private float mPosX; private float mPosY; private float width; private float height; public PinchRecyclerView(Context context) { super(context); if (!isInEditMode()) mScaleDetector = new ScaleGestureDetector(getContext(), new ScaleListener()); } public PinchRecyclerView(Context context, AttributeSet attrs) { super(context, attrs); if (!isInEditMode()) mScaleDetector = new ScaleGestureDetector(getContext(), new ScaleListener()); } public PinchRecyclerView(Context context, AttributeSet attrs, int defStyleAttr) { super(context, attrs, defStyleAttr); if (!isInEditMode()) mScaleDetector = new ScaleGestureDetector(getContext(), new ScaleListener()); } @Override protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) { width = MeasureSpec.getSize(widthMeasureSpec); height = MeasureSpec.getSize(heightMeasureSpec); super.onMeasure(widthMeasureSpec, heightMeasureSpec); } @Override public boolean onInterceptTouchEvent(MotionEvent ev) { try { return super.onInterceptTouchEvent(ev); } catch (IllegalArgumentException ex) { ex.printStackTrace(); } return false; } @Override public boolean onTouchEvent(@NonNull MotionEvent ev) { super.onTouchEvent(ev); final int action = ev.getAction(); mScaleDetector.onTouchEvent(ev); switch (action & MotionEvent.ACTION_MASK) { case MotionEvent.ACTION_DOWN: { final float x = ev.getX(); final float y = ev.getY(); mLastTouchX = x; mLastTouchY = y; mActivePointerId = ev.getPointerId(0); break; } case MotionEvent.ACTION_MOVE: {
thanks
source share