Open pkliang opened 9 years ago
@pkliang
Hi.
Exception occurred?
Digging up this issue as I have the same problem. SlideInLeftAnimationAdapter & SlideInRightAnimationAdapter won't work at least on the first load/display of the data. So if you update the data on your adapter and call notifyDataSetChanged(), everything is shown but without any animation.
It looks like the root cause is the call view.getRootView().getWidth()
which returns 0 in
public class SlideInRightAnimationAdapter [...]
@Override protected Animator[] getAnimators(View view) {
return new Animator[] {
ObjectAnimator.ofFloat(view, "translationX", view.getRootView().getWidth(), 0)
};
}
I am not sure yet how to fix this so that the width is valid. I am using the version 2.2.2.
Got a solution but it may be dirty. In AnimationAdapter.java, method onBindViewHolder, by wrapping the following lines in a post(), the items are animated at the first load.
for (Animator anim : getAnimators(holder.itemView)) {
anim.setDuration(mDuration).start();
anim.setInterpolator(mInterpolator);
}
mLastPosition = adapterPosition;
With the fix holder.itemView.post(new Runnable()...
:
@Override public void onBindViewHolder(final RecyclerView.ViewHolder holder, int position) {
mAdapter.onBindViewHolder(holder, position);
final int adapterPosition = holder.getAdapterPosition();
if (!isFirstOnly || adapterPosition > mLastPosition) {
holder.itemView.post(new Runnable() {
@Override
public void run() {
for (Animator anim : getAnimators(holder.itemView)) {
anim.setDuration(mDuration).start();
anim.setInterpolator(mInterpolator);
}
mLastPosition = adapterPosition;
}
});
} else {
ViewHelper.clear(holder.itemView);
}
}
Thanks to the post the itemView is at least partially rendered and has a proper width. I am not sure about the side effects of this though...
Well, i edited a little to leave from my problem, the onBindViewHolder must be :
@Override
public void onBindViewHolder(RecyclerView.ViewHolder holder, int position)
{
mAdapter.onBindViewHolder(holder, position);
int adapterPosition = holder.getAdapterPosition();
for (Animator anim : getAnimators(holder.itemView))
{
anim.setDuration(mDuration).start();
anim.setInterpolator(mInterpolator);
}
mLastPosition = adapterPosition;
}
Thanks a lot for the great library!!
Thank you. But how does this code help the other developers? These are gradle files & are non-editable. The issue of animation not showing on scroll up is still very much there for me.
Hi, I could only get the AlphaInAnimationAdapter and ScaleInAnimationAdapter work, others, for example SlideInRightAnimationAdapter, do not work.