LayoutAnimation給ListView中的item設(shè)置動態(tài)出場效果(實(shí)例)
LayoutAnimation作用于ViewGroup,為ViewGroup指定一個動畫,當(dāng)它的子元素出場時都按照這個動畫出場。
LayoutAnimation作用于viewgroup有兩種方式:
1. 靜態(tài)的使用xml文件實(shí)現(xiàn)。
2. 在代碼中動態(tài)實(shí)現(xiàn)。
下面用ListView中的item設(shè)置動態(tài)出場效果來分別介紹兩種方式:
靜態(tài)的使用xml文件實(shí)現(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)的實(shí)現(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)出場效果(實(shí)例)就是小編分享給大家的全部內(nèi)容了,希望能給大家一個參考,也希望大家多多支持腳本之家。
相關(guān)文章
Android獲取系統(tǒng)時間以及網(wǎng)絡(luò)時間
這篇文章主要為大家詳細(xì)介紹了Android獲取系統(tǒng)時間以及網(wǎng)絡(luò)時間的方法,感興趣的小伙伴們可以參考一下2016-07-07
Android?Studio實(shí)現(xiàn)音樂播放器的全過程(簡單易上手)
這篇文章主要給大家介紹了關(guān)于Android?Studio實(shí)現(xiàn)音樂播放器的相關(guān)資料,文中通過實(shí)例代碼以及圖文介紹的非常詳細(xì),對各位Android開發(fā)者們具有一定的參考學(xué)習(xí)價值,需要的朋友可以參考下2022-02-02
Android 新手引導(dǎo)蒙層效果實(shí)現(xiàn)代碼示例
本篇文章主要介紹了Android 新手引導(dǎo)蒙層效果實(shí)現(xiàn)代碼示例,具有一定的參考價值,有興趣的可以了解一下。2017-01-01
Android ViewFlipper的詳解及實(shí)例
這篇文章主要介紹了Android ViewFlipper的詳解及實(shí)例的相關(guān)資料,通過本文希望能幫助大家理解這部分內(nèi)容,需要的朋友可以參考下2017-08-08
android開機(jī)自啟動原理與實(shí)現(xiàn)案例(附源碼)
完成一下步驟后,啟動一次程序,完成注冊。等下次手機(jī)開機(jī)時,該軟件即會自動啟動,具體實(shí)現(xiàn)如下,感興趣的朋友可以參考下哈2013-06-06

