Android layoutAnimation詳解及應用
前言:
最近在玩一個APP的時候,發(fā)現(xiàn)剛進入他的頁面,他頁面的子控件都是從右側(cè)飛過來的,感覺好牛逼的樣子,就順便模仿了一個。看著確實是比死板呆在那舒服多了!

還是感覺很好看!反正我覺得比死板呆在那好看!你們覺得那!
在看咱們模仿的:

差不多,在微調(diào)一下就好了!
上點代碼,其實很簡單:
首先新建一個anim文件夾在里面新建兩個xml
<layoutAnimation xmlns:android="http://schemas.android.com/apk/res/android" android:delay="90%" //空間的執(zhí)行間隔 android:animation="@anim/trans" />
<set xmlns:android="http://schemas.android.com/apk/res/android" android:interpolator="@android:anim/accelerate_interpolator"> <translate android:fromXDelta="100%p" android:toXDelta="0" android:duration="200" /> <alpha android:fromAlpha="0" android:toAlpha="1" android:duration="200" /> </set>
只要把這個動畫在布局里面設(shè)置一下就出現(xiàn)這個效果,碉堡了!
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="fill_parent" android:layout_height="fill_parent" android:background="#e6e6e6" android:layoutAnimation="@anim/anim" android:orientation="vertical" > <LinearLayout android:layout_width="match_parent" android:layout_height="wrap_content" android:gravity="center|left" android:background="#ffffff" android:layout_margin="5dip" android:orientation="horizontal" > <ImageView android:layout_width="wrap_content" android:layout_height="wrap_content" android:src="@drawable/ic_launcher" /> <TextView android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="TextView" /> </LinearLayout> <LinearLayout android:layout_width="match_parent" android:layout_height="wrap_content" android:gravity="center|left" android:background="#ffffff" android:layout_margin="5dip" android:orientation="horizontal" > <ImageView android:layout_width="wrap_content" android:layout_height="wrap_content" android:src="@drawable/ic_launcher" /> <TextView android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="TextView" /> </LinearLayout> <LinearLayout android:layout_width="match_parent" android:layout_height="wrap_content" android:gravity="center|left" android:background="#ffffff" android:layout_margin="5dip" android:orientation="horizontal" > <ImageView android:layout_width="wrap_content" android:layout_height="wrap_content" android:src="@drawable/ic_launcher" /> <TextView android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="TextView" /> </LinearLayout> <LinearLayout android:layout_width="match_parent" android:layout_height="wrap_content" android:gravity="center|left" android:background="#ffffff" android:layout_margin="5dip" android:orientation="horizontal" > <ImageView android:layout_width="wrap_content" android:layout_height="wrap_content" android:src="@drawable/ic_launcher" /> <TextView android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="TextView" /> </LinearLayout> <LinearLayout android:layout_width="match_parent" android:layout_height="wrap_content" android:gravity="center|left" android:background="#ffffff" android:layout_margin="5dip" android:orientation="horizontal" > <ImageView android:layout_width="wrap_content" android:layout_height="wrap_content" android:src="@drawable/ic_launcher" /> <TextView android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="TextView" /> </LinearLayout> <LinearLayout android:layout_width="match_parent" android:layout_height="wrap_content" android:gravity="center|left" android:background="#ffffff" android:layout_margin="5dip" android:orientation="horizontal" > <ImageView android:layout_width="wrap_content" android:layout_height="wrap_content" android:src="@drawable/ic_launcher" /> <TextView android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="TextView" /> </LinearLayout> <LinearLayout android:layout_width="match_parent" android:layout_height="wrap_content" android:gravity="center|left" android:background="#ffffff" android:layout_margin="5dip" android:orientation="horizontal" > <ImageView android:layout_width="wrap_content" android:layout_height="wrap_content" android:src="@drawable/ic_launcher" /> <TextView android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="TextView" /> </LinearLayout> </LinearLayout>
就這么簡單的幾句話,感覺用戶體驗頓時上升了不少!真是細節(jié)決定成敗啊!
感謝閱讀,希望能幫助到大家,謝謝大家對本站的支持!
新聞熱點
疑難解答