LayoutAnimation給ListView中的item設(shè)置動態(tài)出場效果(實例)
LayoutAnimation作用于ViewGroup,為ViewGroup指定一個動畫,當它的子元素出場時都按照這個動畫出場。
LayoutAnimation作用于viewgroup有兩種方式:
1. 靜態(tài)的使用xml文件實現(xiàn)。
2. 在代碼中動態(tài)實現(xiàn)。
下面用ListView中的item設(shè)置動態(tài)出場效果來分別介紹兩種方式:
靜態(tài)的使用xml文件實現(xiàn),分為三步
1. 在res的anim目錄(res的文件夾下沒有anim文件夾自己新建一個)下定義LayoutAnimation命名為anim_layout如下:
version="1.0" encoding="utf-8"?> <layoutAnimation xmlns:android="http://schemas.android.com/apk/res/android" android:delay="0.5" android:animation="@anim/anim_item" android:animationOrder="normal" >
其中的delay=“0.5”是指后一個item出場時間比前一個item的出場時間多0.5倍。
animationOrder指的是item的出場順序是正常。
anim_item是指item出場的動畫效果。
2. 在res的anim目錄下定義LayoutAnimation命名為anim_item如下:
<?xml version="1.0" encoding="utf-8"?> <set xmlns:android="http://schemas.android.com/apk/res/android" android:duration="200" > <alpha android:fromAlpha="0.1" android:toAlpha="1" /> <translate android:fromXDelta="500" android:toXDelta="0"/> </set>
1.在listview的布局中加入layoutAnimation。
<ListView android:id="@+id/mylistView" android:layout_width="match_parent" android:layout_height="match_parent" android:layoutAnimation="@anim/anim_layout" > </ListView>
在代碼中動態(tài)的實現(xiàn),分為以下幾步:
Animation animation= AnimationUtils.loadAnimation(this,R.anim.anim_item); LayoutAnimationController controller=new LayoutAnimationController(animation); controller.setDelay(0.5f); listView.setLayoutAnimation(controller);
以上這篇LayoutAnimation給ListView中的item設(shè)置動態(tài)出場效果(實例)就是小編分享給大家的全部內(nèi)容了,希望能給大家一個參考,也希望大家多多支持腳本之家。
相關(guān)文章
Android Studio配合WampServer完成本地Web服務(wù)器訪問的問題
這篇文章主要介紹了Android Studio配合WampServer完成本地Web服務(wù)器訪問,本文給大家介紹的非常詳細,對大家的學(xué)習或工作具有一定的參考借鑒價值,需要的朋友可以參考下2020-10-10調(diào)用startService會拋出IllegalStateException異常解決
這篇文章主要為大家介紹了調(diào)用startService會拋出IllegalStateException異常解決,有需要的朋友可以借鑒參考下,希望能夠有所幫助,祝大家多多進步,早日升職加薪2023-07-07超簡單Android集成華為HMS Scankit 掃碼SDK實現(xiàn)掃一掃二維碼
這篇文章主要介紹了超簡單Android集成華為HMS Scankit 掃碼SDK實現(xiàn)掃一掃二維碼,文中通過示例代碼介紹的非常詳細,對大家的學(xué)習或者工作具有一定的參考學(xué)習價值,需要的朋友們下面隨著小編來一起學(xué)習學(xué)習吧2020-03-03Android通過LIstView顯示文件列表的兩種方法介紹
過ListView顯示SD卡中的文件列表一共有兩種方法,一是:通過繼承ListActivity顯示;二是:利用BaseAdapter顯示,具體實現(xiàn)如下,感興趣的朋友可以參考下哈2013-06-06