Animate the removal of a ListView item

后端 未结 4 1853
生来不讨喜
生来不讨喜 2021-01-30 05:33

I\'m attempting to animate the removal of a ListView item using this:

    mListView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
        @Overr         


        
4条回答
  •  轻奢々
    轻奢々 (楼主)
    2021-01-30 05:56

    I have used the Top to bottom slide animation on refreshing the ListView. Here is the code I used:

     adapter.notifyDataSetChanged();
     Animation animation = AnimationUtils.loadAnimation(
                        getApplication(), R.anim.slide_top_to_bottom);
     getListView().startAnimation(animation);
     getListView().setSelection(0);
    

    and slide_top_to_bottom.xml (save it inside res/anim folder)

    
    
    
    
    
    
    

    EDIT: Try this out:

    mListView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
    @Override
    public void onItemClick(AdapterView adapterView, final View view, final int i, long l) {
    
        ValueAnimator fader = ObjectAnimator.ofFloat(view, "alpha", 1, 0);
        AnimatorSet animation = new AnimatorSet();
        animation.addListener(new AnimatorListener() {
            @Override
            public void onAnimationStart(Animator animation) {
    
            }
            @Override
            public void onAnimationRepeat(Animator animation) {
            }
            @Override
            public void onAnimationEnd(Animator animation) {
    
            }
            @Override
            public void onAnimationCancel(Animator animation) {
            }
        });
        ((AnimatorSet) animation).play(fader);
        animation.setDuration(500);
        animation.start();
        adapter.remove(tasks.get(i));
        adapter.notifyDataSetChanged();
    }
    });
    

提交回复
热议问题