设置gif图像toProgressBar

时间:2016-08-24 11:55:14

标签: android gif progressdialog

我已经使用GIF图像到进度条使用库工作正常但问题是它没有重复动画

loading_dialog = new ProgressDialog(LeadProfile.this, style.MyInnerProgressDialogTheme);
loading_dialog.setCancelable(false);
loading_dialog.setIndeterminateDrawable(GifDrawable.createFromResource(getResources(), drawable.home_loder));
loading_dialog.setProgressStyle(android.R.style.Widget_ProgressBar_Small);
        loading_dialog.show();

任何人都可以帮助我..我甚至使用了自定义窗口视图和自定义对话框它仍然无法正常工作但不重复动画虽然GIF图像有重复

1 个答案:

答案 0 :(得分:0)

您可以使用动画Drawable。 您将需要一系列图像(您可以从gif本身创建它

ActivityDialog

// ImageView that will act as loader. it can be added in `Activity` or `Dialog`
ImageView loading_dialog = (ImageView);
findViewById(R.id.loading_dialog); 

loading_dialog.setBackgroundResource(R.drawable.preloader);
AnimationDrawable animationDrawable = (AnimationDrawable) loading_dialog.getBackground();
animationDrawable = (AnimationDrawable) preLoader.getBackground();

// to start animation
animationDrawable.start();

// to stop animation

animationDrawable.stop();

在drawable文件夹中创建preloader.xml

<?xml version="1.0" encoding="utf-8"?>
<animation-list xmlns:android="http://schemas.android.com/apk/res/android"
    android:oneshot="false" >
<item
    android:drawable="@drawable/preloader1"
    android:duration="45"/>
<item
    android:drawable="@drawable/preloader2"
    android:duration="45"/>
<item
    android:drawable="@drawable/preloader3"
    android:duration="45"/>
<item
    android:drawable="@drawable/preloader4"
    android:duration="45"/>
<item
    android:drawable="@drawable/preloader5"
    android:duration="45"/>

如果您只想更改一次android:oneshot:"true" 你可以拥有与你拍摄的物品一样多的物品。你也可以改变一个图像的持续时间。

相关问题