【问题标题】:Custom Progress Bar with Animation List带有动画列表的自定义进度条
【发布时间】:2016-12-05 18:53:38
【问题描述】:

我想创建一个显示动态图像效果的进度条。为此我创建了一个动画列表并保存在我的可绘制文件夹中。代码如下:

<?xml version="1.0" encoding="utf-8"?>
<animation-list xmlns:android="http://schemas.android.com/apk/res/android" >
    <item android:drawable="@drawable/p_one" android:duration="150" />
    <item android:drawable="@drawable/p_two" android:duration="150" />
    <item android:drawable="@drawable/p_three" android:duration="150" />
    <item android:drawable="@drawable/p_threesix" android:duration="150" />

</animation-list>

之后我像这样使用这个drawable:用于我的ProressBar Drawable

  <ProgressBar
        android:id="@+id/progressBar"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_centerInParent="true"
        android:indeterminate="true"
        android:indeterminateOnly="true"
        android:indeterminateDrawable="@drawable/progress_bar_anim"
        android:visibility="visible" />

问题:运行此代码时没有显示任何内容。为什么 ? 当我使用任何单个图像而不是动画列表可绘制对象时,它会正确显示。有没有其他方法可以做到这一点?

【问题讨论】:

  • 制作 android:duration="250" 并删除 android:indeterminate="true"
  • 这是解决方案吗?????? @MD
  • 不是一个解决方案,只是一个补丁。它在我身边工作得很好......
  • 无效@MD。请检查
  • 阅读AnimationDrawable 文档,您将了解如何运行动画。

标签: android progress-bar iprogressdialog


【解决方案1】:

尝试在&lt;animation-list ..&gt;属性中添加android:oneshot="false",如下所示

<animation-list
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:oneshot="false">
   ...
</animation-list>

android:oneshot="false"

布尔值。如果您想执行一次动画,则为“true”; "false" 循环动画。

Frame animation 的 Android 开发者链接

【讨论】:

    【解决方案2】:

    这里有类似的奇怪问题,我尝试了两个不同的设备,A 工作得很好,B 显示两个水平图像,我在&lt;item&gt; 中添加了&lt;clip&gt;,A 变得不工作,B 工作得很好,所以...最好不要在progressBar中使用&lt;animation-list&gt;...

    【讨论】:

      猜你喜欢
      • 2018-04-04
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2018-11-25
      • 1970-01-01
      • 2017-07-21
      • 1970-01-01
      • 2010-11-26
      相关资源
      最近更新 更多