Android下設定ListView資料載入完成後執行layoutanimation

來源:互聯網
上載者:User

標籤:

今天使用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);

 

這樣就實現了預定的功能,初學不熟悉就是各種糾結,說不準就拐到那個死角就拐不出來了...!  

[email protected]年1月28日11:31:25 - 若不堅強、懦弱給誰來可憐!

Android下設定ListView資料載入完成後執行layoutanimation

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.