我想为ListView的每个项目设置不同的动画效果,即使该列表处于空闲状态,即它不是处于滚动状态也不是掠过状态。我只知道可以通过HandlerRunnable进行连续动画处理,但是不能正常工作。请为此提出建议。

最佳答案

在自定义adpater的getview方法内添加动画。

      @Override
      public View getView(final int position, View convertView, ViewGroup parent) {
        LayoutInflater inflater = (LayoutInflater) context
            .getSystemService(Context.LAYOUT_INFLATER_SERVICE);



        View rowView = inflater.inflate(R.layout.simple_row, parent, false);
        ImageView image = (ImageView) rowView.findViewById(R.id.image);

       if(position==0)
{
        mAnimation = new TranslateAnimation(
                TranslateAnimation.ABSOLUTE, 0f,
                TranslateAnimation.ABSOLUTE, 0f,
                TranslateAnimation.RELATIVE_TO_PARENT, 0f,
                TranslateAnimation.RELATIVE_TO_PARENT, 1.0f);
       mAnimation.setDuration(10000);
       mAnimation.setRepeatCount(-1);//here we set repeat count to unlimited, so that the animation will run continuously
       mAnimation.setRepeatMode(Animation.REVERSE);
       mAnimation.setInterpolator(new LinearInterpolator());
       image.setAnimation(mAnimation);

}

else if(position==1)
{
//your second animation
}


     return rowView;
  }

08-17 16:23