动态显示所有回收站视图项

时间:2017-05-04 19:43:40

标签: android listview gridview android-recyclerview android-animation

我有一个带图像的回收者视图。我可以在点击项目时应用翻转动画。现在我想在倒数计时器用完时将所有图像一起翻转。如何为所有网格项设置动画一次?

这是我的适配器onBindViewHolder的外观,

@Override
    public void onBindViewHolder(final CustomViewHolder viewHolder, final int position) {

        Picasso.with(context).load(imageList.get(position).getImageUrl()).placeholder(R.drawable.placeholder).into(viewHolder.imageView);

        viewHolder.holder.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {

                AnimatorSet setLeftOut = (AnimatorSet) AnimatorInflater.loadAnimator(context,
                        R.animator.crad_flip_right_out);
                AnimatorSet setLeftIn = (AnimatorSet) AnimatorInflater.loadAnimator(context,
                        R.animator.card_flip_left_in);
                setLeftOut.setTarget(viewHolder.frontView);
                setLeftIn.setTarget(viewHolder.backView);
                setLeftOut.start();
                setLeftIn.start();
             }
        });

    }

1 个答案:

答案 0 :(得分:2)

试试这个:

@Override
public void onBindViewHolder(final CustomViewHolder viewHolder, final int position) {

    Picasso.with(context).load(imageList.get(position).getImageUrl()).placeholder(R.drawable.placeholder).into(viewHolder.imageView);

    viewHolder.holder.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            animateView(viewHolder);
        }
    });

}

public void animateViewsOfRecyclerView(){
    for(int i=0;i<recyclerviewAdapter.getCount();++i){
        animateView(recyclerview.findViewHolderForAdapterPosition(i));
    }
}
public void animateView(ViewHolder viewholder){
    AnimatorSet setLeftOut = (AnimatorSet) AnimatorInflater.loadAnimator(context,
            R.animator.crad_flip_right_out);
    AnimatorSet setLeftIn = (AnimatorSet) AnimatorInflater.loadAnimator(context,
            R.animator.card_flip_left_in);
    setLeftOut.setTarget(viewHolder.frontView);
    setLeftIn.setTarget(viewHolder.backView);
    setLeftOut.start();
    setLeftIn.start();
}

每当需要为所有视图设置动画时,请调用方法“animateViewsOfRecyclerView()”。