I have viewpager with layouts as page.I try to remove item with animation on deleteBtn clicked. It almost works if pages wasn't scrolled(activity just loaded with viewpager). In case pages was changed the animation doesn't appear but item remove as usual. Please help me fix animation appearance on delete.
Code of view pager adapter
@Override
public Object instantiateItem(ViewGroup collection, int position) {
LayoutInflater inflater = LayoutInflater.from(context);
ViewGroup layout = (ViewGroup) inflater.inflate(R.layout.item_home_pager, collection, false);
ImageView deleteBtn = (ImageView) layout.findViewById(R.id.like_btn);
deleteBtn.setOnClickListener(v -> {
Animation animation = AnimationUtils.loadAnimation(context, R.anim.slide_to_top);
layout.startAnimation(animation);
removeItem(position);
});
collection.addView(layout);
return layout;
}
public void removeItem(int position) {
personModels.remove(position);
notifyDataSetChanged();
}
@Override
public int getItemPosition(Object object) {
return PagerAdapter.POSITION_NONE;
}
@Override
public void destroyItem(ViewGroup collection, int position, Object view) {
collection.removeView((View) view);
}
@Override
public int getCount() {
return personModels.size();
}
@Override
public boolean isViewFromObject(View view, Object object) {
return view == object;
}