1

In my app there is a Recyclerview in which I want to implement the zoom in / zoom out effect when the user touches an item. I am using an animation to create this effect but it does not work as expected:

  • Items only zoom in and only when I scroll the screen.

  • When expanding, items above and below do not move to expanded item to fit screen

  • Alert: Custom CardView has setOnTouchListener called on it but does not override performClick

Code inside onBindViewHolder:

myViewHolder.card.setOnTouchListener(new View.OnTouchListener() {
            @Override
            public boolean onTouch(View view, MotionEvent motionEvent) {

                if (motionEvent.getAction() == MotionEvent.ACTION_MOVE){
//                        Toast.makeText(context, "MOVE ...", Toast.LENGTH_SHORT).show();
                    return true;
                }else if (motionEvent.getAction() == MotionEvent.ACTION_DOWN){
                    Toast.makeText(context, "DOWN ...", Toast.LENGTH_SHORT).show();
                    myViewHolder.card.setAnimation(AnimationUtils.loadAnimation(context,R.anim.zoom_in));
                    return true;
                }else if(motionEvent.getAction() == MotionEvent.ACTION_UP){
                    myViewHolder.card.setAnimation(AnimationUtils.loadAnimation(context,R.anim.zoom_out));
                    Toast.makeText(context, "UP ...", Toast.LENGTH_SHORT).show();
                    return true;
                }
                return false;
            }
        });

Zoom out and zoom in:

<scale
    android:duration="750"
    android:fromXScale="1.1"
    android:fromYScale="1.1"
    android:pivotX="50%"
    android:pivotY="50%"
    android:toXScale="1"
    android:toYScale="1" >
</scale>

<scale
    android:duration="750"
    android:fromXScale="1"
    android:fromYScale="1"
    android:pivotX="50%"
    android:pivotY="50%"
    android:toXScale="1.25"
    android:toYScale="1.25" >
</scale>

How can I make items move correctly? Thanks in advance.

Vitor Ferreira
  • 1,075
  • 1
  • 14
  • 28
  • Take a look on this mate https://stackoverflow.com/questions/35309710/zoom-central-image-recycler-view – Abhishek Sep 03 '19 at 13:25

1 Answers1

0

Regardless of your Recyclerview or whatever other View, You can't go that way easy my recommendation is you to follow some best practices, basically that functionality is reserved for Accessibility Features, some kind of tools for vision disability people, so creating one app with that feature is useless if the whole smartphone is not configured with accessibility features, so the technique you want to perform is called Magnification, that feature need to be selected and then your app automatically will do exactly as you want without programming some extra features for that, if you create that feature, and someone has already the accessibility features is very posible that your feature won't have priority in the behavior. or just wont work at all.

Magnification: With magnification, you get into the accessibility features that could prove useful to Android owners who do not have a disability. Triple-tap to zoom in or out, and triple-tap and hold to magnify what was under your finger. Useful for older users or for use with apps that don't scale well on smaller devices.

I recommend you to visit and check this documentation, to create a great user experience app.

https://developer.android.com/guide/topics/ui/accessibility

toddsalpen
  • 411
  • 4
  • 9