Android ApiDemos樣本解析(126):Views->Layout Animation-&am

來源:互聯網
上載者:User

LayoutAnimationController 用來為一個layout 或是viewgroup 包含的子view添加動畫效果, Layout中的每個元素都會採用同一個動畫效果,但開始時間不同。 子View動畫的預設開始時間為子View在Layout中的序號index 乘以 一個固定的時間間隔。 LayoutAnimationController 的子類可以重載getDelayForView(android.view.View)為子View定義動畫開始時間,如GridLayoutAnimationController 根據子View的行和列來計運算元View動畫的開始時間。

本例為一GridView 設定Fade淡入 動畫,使用App Launcher 中的表徵圖作為資料來源,

為GridView 設定LayoutAnimation:

<GridView xmlns:android=”http://schemas.android.com/apk/res/android”
android:id=”@+id/grid”
android:layoutAnimation=”@anim/layout_grid_fade”

android:layout_width=”match_parent”
android:layout_height=”match_parent”
android:padding=”10dp”
android:verticalSpacing=”10dp”

android:horizontalSpacing=”10dp”
android:numColumns=”auto_fit”
android:columnWidth=”60dp”
android:stretchMode=”columnWidth”

android:gravity=”center” />

layout_grid_fade.xml 定義如下:

<gridLayoutAnimation
xmlns:android=”http://schemas.android.com/apk/res/android”
android:rowDelay=”50%”
android:directionPriority=”column”
android:animation=”@anim/fade” />

gridLayoutAnimation 為Grid中每個Cell定義對應的動畫效果android:animation=@ anim/fade .
columnDelay:  定義GridView列 動畫延遲時間比率
direction:  定義動畫依次發生的方向。
directionPriority:  動畫發生的次序以行或是列優先。
rowDelay:  定義GridView行 動畫延遲時間比率
gridLayoutAnimation 為GridView定義了子Cell依次開始動畫的順序,每個Cell具體的動畫由android:animation定義,本例使用@anim/fade 定義Grid每個Cell的動畫效果(淡入)。

<alpha xmlns:android=”http://schemas.android.com/apk/res/android”
android:interpolator=”@android:anim/accelerate_interpolator”
android:fromAlpha=”0.0″ android:toAlpha=”1.0″
android:duration=”@android:integer/config_longAnimTime” />

 

 

 

作者:mapdigit

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在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.