我希望使用不同的动画为ListView
的每个项目设置动画,即使列表处于空闲状态,即它不是滚动或投掷状态。我只知道可以通过Handler
和Runnable
来完成连续动画,但它无法正常工作。请为此提出建议。
答案 0 :(得分:1)
在自定义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;
}