zoukankan      html  css  js  c++  java
  • Android下设置ListView数据加载完成后执行layoutanimation

    今天使用android的volley框架写了一个简单的网络天气获取的demo。

    承载数据的空间是ListView

    因为是网络加载,必然先要设置ListView的默认数据,我设置的就是那个Loading...

    然后从网络获取到数据后,再解析,然后更新到adapter,然后notifyDataSetChanged更新数据到ListView。

    可是ListView设置了layoutanimation,这样默认的ListView打开后那个Loading执行了动画,当网络数据加载完毕后,

    layoutanimation就不会再次执行了!

    网上搜索无果,可能是新手,不太熟悉,发到CSDN上也没有人回答我!

    最后自己研究发现,自己使用的是XML的方式设置的layoutanimation,所以ListView加载后就开始执行了!

    <ListView
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:id="@+id/listView"
            android:layout_centerVertical="true"
            android:layoutAnimation="@anim/list_anim_layout2"
            android:layout_centerHorizontal="true"/>

    于是想到用代码执行animation,先把所有animation加载,然后网络数据加载完毕并更新到Listview后再把animation绑定到Listview上。

     1 private LayoutAnimationController lac;
     2 
     3 // --  @加载ListView的layoutanimation动画
     4     lac=AnimationUtils.loadLayoutAnimation(WeatherActivity.this,R.anim.list_anim_layout2);
     5 
     6 //after response
     7 .......
     8 // --  @更新数据到ListView
     9 adapter.notifyDataSetChanged();
    10 // --  @加载完成后设置layoutanimation执行动画效果
    11 listVview.setLayoutAnimation(lac);

    这样就实现了预定的功能,初学不熟悉就是各种纠结,说不准就拐到那个死角就拐不出来了...!  

    waitfate@2015年1月28日11:31:25 - 若不坚强、懦弱给谁来可怜!

  • 相关阅读:
    HashMap
    Spring事务异常回滚,捕获异常不抛出就不会回滚(转载) 解决了我一年前的问题
    脏读 不可重复读 幻读
    冒泡优化
    Class.forName的作用以及为什么要用它【转】
    java反射入门
    Java异常分类 转载
    转载 【CSS进阶】伪元素的妙用--单标签之美
    转载文章 利用旋转正方形与图形的组合实现爱心
    Three.js基础学习【修改版】
  • 原文地址:https://www.cnblogs.com/waitfate/p/4255341.html
Copyright © 2011-2022 走看看