如何将自定义微调器图像应用于android中的进度对话框

Sal*_*roy 9 android progressdialog

我想在android中使用自定义微调器图像来进行dialod我为此目的使用.gif文件,并通过此代码应用它,

dialog = new ProgressDialog(BackupRestoreActivityContext);    
dialog.setCancelable(true);    
dialog.setIcon(resId);    
dialog.setTitle(title);    
dialog.setProgressStyle(ProgressDialog.STYLE_SPINNER);    
dialog.setIndeterminate(true);
dialog.setIndeterminateDrawable(BackupRestoreActivityContext.getResources().getDrawable(R.drawable.bar));    
dialog.show();
Run Code Online (Sandbox Code Playgroud)

通过此代码Spinner图像更改为bar.gif但它没有旋转,请帮助我这是错误的,谢谢任何帮助在这方面非常感谢.

pca*_*ans 9

在Android中,动画gif在ImageView中不起作用.您需要将它们作为电影播放,如示例ApiDemos所示.

但是你可以在多个文件中爆炸你的gif并创建一个动画资源文件.动画文件是一个xml文件,描述要显示的drawable列表和每个帧的持续时间(如果可以使用它们,则应用转换).您可以在此处阅读官方文档中的详细信息:http: //developer.android.com/guide/topics/resources/animation-resource.html#Frame

这个drawable应该可以在ProgressDialog中很好地工作


小智 9

我的回答有点晚了,你可以这样做:

1.-制作动画可绘画

例如:my_animation.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/myImage1"
        android:duration="200"/>
    <item
        android:drawable="@drawable/myImage2"
        android:duration="200"/>
...


</animation-list>
Run Code Online (Sandbox Code Playgroud)

2.-在您的活动电话中

dialog = new ProgressDialog(BackupRestoreActivityContext);    
dialog.setCancelable(true);    
dialog.setIcon(resId);    
dialog.setTitle(title);    
dialog.setProgressStyle(ProgressDialog.STYLE_SPINNER);    
dialog.setIndeterminate(true);
dialog.setIndeterminateDrawable(BackupRestoreActivityContext.getResources().getDrawable(R.drawable.my_animation));
dialog.show();
Run Code Online (Sandbox Code Playgroud)