In my recyclerview, I want all items to jiggle/wobble/wiggle when a user holds an item and moves it. The problem I'm facing is that when a user holds the item and moves it in the same viewtype the wiggle is okay but when someone drags it to the top of the recyclerview (which is a header created as a viewtype in the recyclerview) the wiggle increases a lot.
On playing around with the values I realised that this was because even though the rotation angle the same, the farther it moved away from the item's center the rotation used to increase.
I tried doing this with an object animator also but it didn't help as that too had the same issue of the rotation angle.
Here is my wiggle code
<rotate xmlns:android="http://schemas.android.com/apk/res/android"
android:duration="100"
android:fromDegrees="-5"
android:pivotX="50%"
android:pivotY="50%"
android:repeatCount="infinite"
android:repeatMode="reverse"
android:toDegrees="5" />
Here is a video of how it looks - link
On bindView logic to start animating
((VHItem) holder).rlContainer.setOnLongClickListener(new View.OnLongClickListener()
{
@Override
public boolean onLongClick(View view)
{
if (buPostModelList != null)
{
startAnimationItem = true;
isDragCover = true;
isEditCoverImage = false;
for (int i = 0; i <= buPostModelList.size(); i++)
{
if (recyclerView.getChildAt(i) != null && recyclerView.getChildViewHolder(recyclerView.getChildAt(i)).getItemViewType() != TYPE_HEADER)
{
recyclerView.getChildAt(i).startAnimation(AnimationUtils.loadAnimation(context, R.anim.jiggle));
}
}
touchHelper.startDrag(holder);
}
return true;
}
});
EDIT A Sample project - link
from How to use a rotate animation while dragging view so center position keeps changing? To solve fromDegree toDegree issue
No comments:
Post a Comment