Android 如何使用无限动画效果?

Android 如何使用无限动画效果?,android,Android,我正在用java开发一个应用程序,android studio 我有一个动态填充的ListView,其中包含一个图像 public class adapterListProd extends BaseAdapter { private final List<Produto> Produtos; private final Activity act; private final Contex

我正在用java开发一个应用程序,android studio

我有一个动态填充的ListView,其中包含一个图像

public class adapterListProd extends BaseAdapter {
                private final List<Produto> Produtos;
                private final Activity act;
                private final Context ctx;
                private AlertDialog alerta;

                public Double precoAtual;

                public adapterListProd(List<Produto> Produtos, Activity act, Context ctx) {
                    this.Produtos = Produtos;
                    this.act = act;
                    this.ctx = ctx;
                }

                /*public adapterListProd(List<String> nomeProdutos,List<Integer> imageProdutos, Activity act) {
                    this.Produtos = Produtos;
                    this.act = act;
                }*/

                @Override
                public int getCount() {

                    return Produtos.size();
                }

                @Override
                public Object getItem(int position) {

                    return Produtos.get(position);
                }

                @Override
                public long getItemId(int position) {

                    return Produtos.get(position).getId();
                }


                @Override
                public View getView(int position, View convertView, ViewGroup parent) {

                    final DecimalFormat formato = new DecimalFormat("#.00");


                    final Produto Prod = Produtos.get(position);
                    View view;
                    TextView nome;
                    ImageView imagem;
                    imagem = (ImageView) view.findViewById(R.id.img);
                    imagem.setImageDrawable(Prod.getImagem());
    }
  }
我相信我不能同时使用一个,因此listView构造将被卡在第一项中


我该怎么做?

这里有两个不同的动画,一个用于幻灯片右侧,另一个用于幻灯片左侧。。 我建议您使用android AnimatorSet以避免如下循环:-

 final AnimatorSet animatorSet = new AnimatorSet();
    ObjectAnimator animateLeft = ObjectAnimator.ofFloat(imagem, "translationX", 0, 10f);
    ObjectAnimator animateRight = ObjectAnimator.ofFloat(imagem, "translationX", 10f, 0);
    animatorSet.playSequentially(animateLeft, animateRight);

    animatorSet.start();
    animatorSet.addListener(new AnimatorListenerAdapter() {
        @Override
        public void onAnimationEnd(Animator animation) {
            animatorSet.start();
        }
    });
因此,无论何时动画完成,都可以再次开始动画。 10是要相对于每个ObjectAnimator在x轴上平移imageview的距离


我希望这将帮助您

无需使用回调方法就可以再次启动动画,所以下面的代码就足以做到这一点

animation.setRepeatCount(Animation.INFINITE);

是的,但是如果我们有一个视图,其中我们想要无限地应用左右两个不同的动画,那么如何使用动画来实现呢
animation.setRepeatCount(Animation.INFINITE);