如何在Android中创建像Image一样的进度条

时间:2016-01-27 04:42:48

标签: android android-layout android-widget progress-bar

如何在我的Android应用中创建以下图像类型的进度环。我希望在我的整个应用程序加载到设备之前显示它10秒。而且我想旋转它。像窗口设备旋转。任何帮助表示赞赏。我是Andorid的新手。

图片:

enter image description here

5 个答案:

答案 0 :(得分:9)

我得到了完美的答案。

使用此链接我找到了圆形进度环。

progress_bar.gif

然后我使用此代码:

<强> animation.xml

<?xml version="1.0" encoding="utf-8"?>
<animated-rotate xmlns:android="http://schemas.android.com/apk/res/android"
    android:drawable="@drawable/progress_bar"
    android:pivotX="50%"
    android:pivotY="50%" />

在我的主要xml文件中。

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"          android:layout_width="match_parent"
    android:layout_height="match_parent" android:paddingLeft="@dimen/activity_horizontal_margin"
    android:paddingRight="@dimen/activity_horizontal_margin"
    android:paddingTop="@dimen/activity_vertical_margin"
    android:paddingBottom="@dimen/activity_vertical_margin" tools:context=".MainActivity">


    <ProgressBar
        android:id="@+id/progressbar1"
        android:layout_marginTop="80dp"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:indeterminateDrawable="@anim/animation"/>


</RelativeLayout>

最后输出是:

enter image description here

答案 1 :(得分:4)

Modifying the resource image of Progress Bar - 最近在这里讨论了这个问题。看看吧。

简而言之 - 您可以使用

  • custom drawable
  • 动画列表

这两种方法都可以像你那样创建进度条。

答案 2 :(得分:4)

您可以使用此库以更简单的方式执行此操作。此外,还有很多直观的progressBar类型。

https://github.com/81813780/AVLoadingIndicatorView

答案 3 :(得分:4)

你可以使用gifView库:https://github.com/koral--/android-gif-drawable

使用这是你的.xml: -

<pl.droidsonroids.gif.GifImageView
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:src="@drawable/src_anim"
    />

其中src_anim是您的加载程序gif文件

答案 4 :(得分:1)

使用 Lottie 动画。 参见:https://github.com/airbnb/lottie-android 库中的LottieDrawable包含方法 progress(),如果加载的图像是进度图像,该方法将设置正确的帧。