LayoutAnimation給ListView中的item設(shè)置動(dòng)態(tài)出場(chǎng)效果(實(shí)例)
LayoutAnimation作用于ViewGroup,為ViewGroup指定一個(gè)動(dòng)畫(huà),當(dāng)它的子元素出場(chǎng)時(shí)都按照這個(gè)動(dòng)畫(huà)出場(chǎng)。
LayoutAnimation作用于viewgroup有兩種方式:
1. 靜態(tài)的使用xml文件實(shí)現(xiàn)。
2. 在代碼中動(dòng)態(tài)實(shí)現(xiàn)。
下面用ListView中的item設(shè)置動(dòng)態(tài)出場(chǎng)效果來(lái)分別介紹兩種方式:
靜態(tài)的使用xml文件實(shí)現(xiàn),分為三步
1. 在res的anim目錄(res的文件夾下沒(méi)有anim文件夾自己新建一個(gè))下定義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”是指后一個(gè)item出場(chǎng)時(shí)間比前一個(gè)item的出場(chǎng)時(shí)間多0.5倍。
animationOrder指的是item的出場(chǎng)順序是正常。
anim_item是指item出場(chǎng)的動(dòng)畫(huà)效果。
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>
在代碼中動(dòng)態(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è)置動(dòng)態(tài)出場(chǎng)效果(實(shí)例)就是小編分享給大家的全部?jī)?nèi)容了,希望能給大家一個(gè)參考,也希望大家多多支持腳本之家。
相關(guān)文章
Android獲取系統(tǒng)時(shí)間以及網(wǎng)絡(luò)時(shí)間
這篇文章主要為大家詳細(xì)介紹了Android獲取系統(tǒng)時(shí)間以及網(wǎng)絡(luò)時(shí)間的方法,感興趣的小伙伴們可以參考一下2016-07-07
Android?Studio實(shí)現(xiàn)音樂(lè)播放器的全過(guò)程(簡(jiǎn)單易上手)
這篇文章主要給大家介紹了關(guān)于Android?Studio實(shí)現(xiàn)音樂(lè)播放器的相關(guān)資料,文中通過(guò)實(shí)例代碼以及圖文介紹的非常詳細(xì),對(duì)各位Android開(kāi)發(fā)者們具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友可以參考下2022-02-02
Android 新手引導(dǎo)蒙層效果實(shí)現(xiàn)代碼示例
本篇文章主要介紹了Android 新手引導(dǎo)蒙層效果實(shí)現(xiàn)代碼示例,具有一定的參考價(jià)值,有興趣的可以了解一下。2017-01-01
Android ViewFlipper的詳解及實(shí)例
這篇文章主要介紹了Android ViewFlipper的詳解及實(shí)例的相關(guān)資料,通過(guò)本文希望能幫助大家理解這部分內(nèi)容,需要的朋友可以參考下2017-08-08
android開(kāi)機(jī)自啟動(dòng)原理與實(shí)現(xiàn)案例(附源碼)
完成一下步驟后,啟動(dòng)一次程序,完成注冊(cè)。等下次手機(jī)開(kāi)機(jī)時(shí),該軟件即會(huì)自動(dòng)啟動(dòng),具體實(shí)現(xiàn)如下,感興趣的朋友可以參考下哈2013-06-06
Android RecyclerView使用入門(mén)介紹
RecyclerView是Android一個(gè)更強(qiáng)大的控件,其不僅可以實(shí)現(xiàn)和ListView同樣的效果,還有優(yōu)化了ListView中的各種不足。其可以實(shí)現(xiàn)數(shù)據(jù)縱向滾動(dòng),也可以實(shí)現(xiàn)橫向滾動(dòng)(ListView做不到橫向滾動(dòng))。接下來(lái)講解RecyclerView的用法2022-10-10

