標籤:
今天使用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