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.