您好我想在我的图库中设置imageViews的动画(虽然我知道它已被弃用),而图像正在下载。它适用于看起来很糟糕的动画集,但我很想拥有一个类似旋转的Android进度指示器。我现在已经搜索了几个小时,发现没有什么可以解决我的问题。
// getView of my ImageAdapter for gallery
public View getView(int position, View convertView, ViewGroup parent)
{
...
if(image != null){
//set the downloaded image and stop animation
imageView.setAnimation(null);
imageView.setImageBitmap(images.get(position));
}
else{
//display loading animation
// this works - but looks crappy
//R.drawable.loading is animation-set with 5 images
//imageView.setBackgroundResource(R.drawable.loading);
//AnimationDrawable anim = (AnimationDrawable) imageView.getBackground();
//anim.start();
//this leads to my problem
//R.drawable.loading_circle is .png which looks like the android one
//R.anim.rotate is infinite 360 degree rotation
imageView.setBackgroundResource(R.drawable.loading_circle); // wont work with .setImageResource() too
imageView.startAnimation(AnimationUtils.loadAnimation(imageView.getContext(), R.anim.rotate));
}
...
}
但这不会按预期工作(我创建了一个显示我的问题的图像 - 但我无法发布它 - 所以这里是一个链接http://s1.directupload.net/images/140807/kmws7pi2.png)...
提前致谢!
答案 0 :(得分:0)
执行类似
的操作在drawable文件夹中创建animantion.xml并粘贴参考动画图像的代码
<item android:drawable="@drawable/app00000" android:duration="300"/>
<item android:drawable="@drawable/app00001" android:duration="300"/>
<item android:drawable="@drawable/app00002" android:duration="300"/>
<item android:drawable="@drawable/app00003" android:duration="300"/>
<item android:drawable="@drawable/app00004" android:duration="300"/>
在你的else语句中使用以下代码
imageView.setBackgroundResource(R.drawable.animation);//animation.xml reference here
final AnimationDrawable frameAnimation = (AnimationDrawable) imageView.getBackground();
if(frameAnimation.isRunning()){
frameAnimation.stop();
}else{
frameAnimation.stop();
frameAnimation.start();
}