【问题标题】:Android indeterminate progress as ImageView sourceAndroid不确定进度作为ImageView源
【发布时间】:2012-06-12 02:06:41
【问题描述】:

我有一个ImageView,我想在图像加载之前显示一个不确定的进度微调器。理想情况下,我想从我的布局 xml 文件中指向可绘制对象本身,然后简单地在代码中交换图像。

这是drawable的xml;它显示的只是一个不会旋转的静态图像。

<animated-rotate
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:drawable="@drawable/spinner"
    android:fromDegrees="0"
    android:toDegrees="360"
    android:pivotX="50%"
    android:pivotY="50%"
    android:repeatCount="infinite"
    android:duration="500" />

我也尝试过只使用&lt;rotate&gt; 根标签,结果是一样的。我有什么遗漏吗?

【问题讨论】:

  • 如何在代码中调用动画?
  • 我必须从代​​码中调用它吗?它不能只是一个存在于 res/drawable 中的 xml,并且 imageview 会知道对其进行动画处理吗?
  • 是的,你必须从代码中调用它

标签: android animation progress-bar imageview progress


【解决方案1】:

我以一种更简单的方式解决了我自己的问题。我有一个FrameLayout 和两个孩子:自定义ImageView 和一个不确定的ProgressBar。图片加载完成后,我将 ProgressBar 设为消失。

【讨论】:

    【解决方案2】:

    从你的动画文件夹中加载动画,然后调用 startAnimation 来播放它:

    final ImageView ivRotate = (ImageView) findViewById(R.id.iv_rotate);
    Animation rotate = AnimationUtils.loadAnimation(this, R.anim.rotate_picture);
    ivRotate.startAnimation(rotate);
    

    【讨论】:

    • 这会旋转整个ImageView,包括背景。如何仅使源图像(当前为微调器)旋转?
    • @Karakuri:让背景透明。
    • 这仍然会旋转整个视图,而不是图像本身。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多