【问题标题】:rotate a refresh button in ListView旋转 ListView 中的刷新按钮
【发布时间】:2014-11-11 02:01:56
【问题描述】:

最近我写了一个函数。它是关于每个列表项中的刷新按钮。我想要的是单击按钮或列表项,刷新按钮开始旋转。请求完成时停止。 我使用动画如下:

<?xml version="1.0" encoding="UTF-8"?>
<rotate xmlns:android="http://schemas.android.com/apk/res/android"
    android:duration="1000"
    android:fillAfter="true"
    android:fromDegrees="0"
    android:interpolator="@android:anim/linear_interpolator"
    android:pivotX="50%"
    android:pivotY="50%"
    android:repeatCount="infinite"
    android:toDegrees="358" />

还有一些源代码在这里:

public void refresh(View v) {

    Animation rotation = AnimationUtils.loadAnimation(mContext,
            R.anim.rotate);
    rotation.setFillAfter(true);
    v.startAnimation(rotation);

}

public void completeRefresh(View v) {
    v.clearAnimation();
}

请求完成后,我调用 notifyDataSetChanged() 来刷新 LiseView。

问题是按钮确实在旋转。但是当我第二次点击它时。它在旋转,但有点模糊。就像这样:

有什么建议吗?非常感谢。

【问题讨论】:

  • 我用谷歌搜索的所有方法都试过了。但没有任何效果...
  • 我想你可以在这里使用 GIF 图片。这对你会更好。
  • 最后我发现当我删除谷歌广告横幅时。它就像一个魅力。我还没有时间确切地知道原因。我们去看看吧。

标签: android listview rotation imagebutton rotateanimation


【解决方案1】:

第二次(以及后续点击)最有可能发生的情况是动画再次在其上运行。

在您当前的实现中,尝试像这样使用setTag(...)

public void refresh(View v) {
    if(v.getTag() != null && (boolean)v.getTag()) {
        //do nothing, since we are setting the tag to be true once pressed
    } else {
        //this view hasn't been clicked yet, show animation and set tag
        v.setTag(true);
        Animation rotation = AnimationUtils.loadAnimation(mContext, R.anim.rotate);
        rotation.setFillAfter(true);
        v.startAnimation(rotation);
    }
}

在您的适配器中,您应该跟踪正在为哪些列表项设置动画(我假设可以同时单击多个项目)。一旦您知道“请求”已完成,您可以使用正确的项目更新适配器,然后调用 notifyDataSetChanged()

【讨论】:

  • 谢谢。最后我发现当我删除谷歌广告横幅时。它就像一个魅力。我还没有时间确切地知道原因。我们去看看吧。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2015-09-08
  • 2012-09-09
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多