【问题标题】:Android Listview Refresh animationAndroid Listview 刷新动画
【发布时间】:2010-12-03 20:56:49
【问题描述】:

我有一个简单的 ListView,它显示来自数据库的数据。每隔 1 分钟,数据就会自动刷新。这是我用来执行此操作的代码 sn-p:

DataAdapter adp = (DataAdapter) DataList.getAdapter();
adp.UpdateDataList(DataAdapter.DATA_LIST);
adp.notifyDataSetChanged();
DataList.invalidateViews();
DataList.scrollBy(0, 0);

我创建了 ListView,即 DataView 和 dataAdapter,它们只是扩展了 baseAdapter。 UpdateDataList 只是从数据库中获取数据并创建一个arrayList。 并且适配器通知视图刷新数据。

一切都很完美。 现在我在这里尝试做的一件事是,当数据刷新时,我需要添加某种动画,使其变得引人注目。人们会标记出发生了什么事。

类似于 iPhone 应用程序。我不想添加微调器,因为数据更新是同步过程,因此数据更改很快,无需在视图中进行任何新更改。只是数字被翻转了。

任何帮助将不胜感激......

【问题讨论】:

    标签: android listview animation


    【解决方案1】:

    这是我尝试过并为我工作的代码......

    /* Setting up Animation */
            AnimationSet set = new AnimationSet(true);
    
              Animation animation = new AlphaAnimation(0.0f, 1.0f);
              animation.setDuration(400);
              set.addAnimation(animation);
    
              animation = new TranslateAnimation(
                  Animation.RELATIVE_TO_SELF, 0.0f, Animation.RELATIVE_TO_SELF, 0.0f,
                  Animation.RELATIVE_TO_SELF, -1.0f, Animation.RELATIVE_TO_SELF, 0.0f
              );
              animation.setDuration(400);
              set.addAnimation(animation);
    
              LayoutAnimationController controller =
                  new LayoutAnimationController(set, 0.25f);
              parent.setLayoutAnimation(controller);
              /* Animation code ends */
    

    【讨论】:

    • 这看起来很酷..@Hims
    • 它很好,但每次运行 notifyDataSetChanged 动画都会开始启动。如何解决这个问题?
    【解决方案2】:

    也许您可以将动画附加到您的 ListView,因为 ListView 扩展了 ViewGroup,您可以这样做,请阅读 android 参考上的 LayoutAnimationController:http://developer.android.com/reference/android/view/animation/LayoutAnimationController.html

    干杯

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2020-02-09
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多