带有 .gif 文件的 Android 自定义进度条 [英] Android custom progress bar with .gif file
问题描述
在我的应用程序中,我有一个自定义进度条
In my app i have a custom progress bar
进度.xml
<ProgressBar
android:id="@+id/progressBar1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerInParent="true"
android:progressDrawable="@drawable/loader" />
我的gif文件
我想用这张图片创建一个进度条
I want to create a progress bar with this image
换句话说,每当我从服务器下载数据并在下载数据后将其删除时,我都想显示此图像
In other word i want to show this image whenever i download data from server and remove it after downloading the data
或者你可以说,如何将此图像显示为进度条
or you can say , how to show this image as a progress bar
推荐答案
首先将您的 Gif 图像转换为 png 切片图像序列.
First Conver your Gif image to png Slice image sequence.
将您的进度条声明为图像视图.
Declare Your Progress bar as Image view.
<ImageView android:id="@+id/main_progress" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_gravity="center" android:visibility="visible" />
使用从 gif 生成的 .png 序列图像在 drawable 文件夹中创建 .xml 文件.在这种情况下,Loading_web_animation.xml
Create .xml file in drawable folder using your .png sequence image those are generated from gif. In this case, Loading_web_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="@mipmap/wblod_0" android:duration="40" /> <item android:drawable="@mipmap/wblod_1" android:duration="40" /> <item android:drawable="@mipmap/wblod_2" android:duration="40" /> <item android:drawable="@mipmap/wblod_3" android:duration="40" /> <item android:drawable="@mipmap/wblod_4" android:duration="40" /> <item android:drawable="@mipmap/wblod_5" android:duration="40" /> <item android:drawable="@mipmap/wblod_6" android:duration="40" /> <item android:drawable="@mipmap/wblod_7" android:duration="40" /> <item android:drawable="@mipmap/wblod_8" android:duration="40" /> <item android:drawable="@mipmap/wblod_9" android:duration="40" /> <item android:drawable="@mipmap/wblod_10" android:duration="40" /> <item android:drawable="@mipmap/wblod_11" android:duration="40" /> </animation-list>
在 Main Activity 中设置如下代码,
In Main Activity set the code like,
private AnimationDrawable animationDrawable; private ImageView mProgressBar; mProgressBar.setBackgroundResource(R.drawable.loading_web_animation); animationDrawable = (AnimationDrawable)mProgressBar.getBackground(); mProgressBar.setVisibility(View.VISIBLE); animationDrawable.start(); mProgressBar.setVisibility(View.GONE); animationDrawable.stop();`
这篇关于带有 .gif 文件的 Android 自定义进度条的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!