【问题标题】:Android Gallery animated loading spinner while images are downloaded下载图像时的 Android Gallery 动画加载微调器
【发布时间】:2014-09-30 14:53:44
【问题描述】:

嗨,我想在下载图像时为我的画廊中的 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)...

  • 只有在 Gallery 的 imageView 包含图像时才会启动动画(但无论如何动画都应该停止)
  • 只有在 imageView 为空时,动画才会随 imageView 一起移动

提前致谢!

【问题讨论】:

  • 您放置图像的列表视图项布局.. 放置进度条并使进度条(圆形)可见并隐藏图像视图。下载图像时隐藏进度条并显示带有下载图像集的图像视图。
  • 这并不容易,因为我使用的是画廊而不是水平列表视图或类似的东西......我不能(或不知道是否可能)将画廊内的 imageView 设置为布局

标签: android animation imageview gallery


【解决方案1】:

做类似的事情

  1. 在可绘制文件夹中创建 animation.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();
                }

【讨论】:

  • 嗨 - 这正是我所拥有的并且有效 - 但它看起来很糟糕......我想要的是我在 imageView 中将“进度指示器”设置为 .png 然后开始旋转动画 - 看起来比动画集更流畅...
猜你喜欢
  • 2013-04-10
  • 2019-11-16
  • 2022-01-20
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2011-11-18
相关资源
最近更新 更多