ILayoutAnimationController動(dòng)畫布局
自定義 LayoutAnimationController,可任意定制 ViewGroup 實(shí)例內(nèi)部子 View 的動(dòng)畫執(zhí)行順序,1行代碼就讓你的ViewGroup擁有華麗的布局動(dòng)畫!
使用方法
方法一:
首先創(chuàng)建 ILayoutAnimationController 實(shí)例,然后將此實(shí)例作為參數(shù)為 ViewGroup 設(shè)置布局動(dòng)畫
- 1:{@link ILayoutAnimationController#generateController(Animation, float, ILayoutAnimationController.IndexAlgorithm)}
- 2:{@link android.view.ViewGroup#setLayoutAnimation(LayoutAnimationController)}
方法二:
1行代碼直接搞定,以下兩種方法任選
- {@link ILayoutAnimationController#setLayoutAnimation(ViewGroup, int, float, ILayoutAnimationController.IndexAlgorithm)}
- {@link ILayoutAnimationController#setLayoutAnimation(ViewGroup, Animation, float,ILayoutAnimationController.IndexAlgorithm)}
示例代碼:
LinearLayout ll = (LinearLayout) findViewById(R.id.ll);
//兩行代碼設(shè)置布局動(dòng)畫:
ILayoutAnimationController controller = ILayoutAnimationController.generateController(AnimationUtils.loadAnimation(this,R.anim.activity_open_enter),0.8f,ILayoutAnimationController.IndexAlgorithm.INDEXSIMPLEPENDULUM);
ll.setLayoutAnimation(controller);
//一行代碼直接搞定:
ILayoutAnimationController.setLayoutAnimation(ll,R.anim.activity_open_enter,0.8f,ILayoutAnimationController.IndexAlgorithm.INDEXSIMPLEPENDULUM);
方法setLayoutAnimation中各參數(shù)介紹:
/**
* 根據(jù)傳入的動(dòng)畫資源ID、單個(gè)子View動(dòng)畫延時(shí)、子View動(dòng)畫執(zhí)行順序算法枚舉值 創(chuàng)建一個(gè)新的CustomLayoutAnimationController實(shí)例,
* 將此實(shí)例作為參數(shù)為viewGroup設(shè)置布局動(dòng)畫
* @param viewGroup
* @param animResId
* @param delay
* @param indexAlgorithm
*/
public static void setLayoutAnimation(@NonNull ViewGroup viewGroup,@AnimRes int animResId, float delay,@Nullable final IndexAlgorithm indexAlgorithm){
Animation animation = AnimationUtils.loadAnimation(viewGroup.getContext(),animResId);
setLayoutAnimation(viewGroup,animation,delay,indexAlgorithm);
}
注意
使用 ILayoutAnimationController 獲取的 ILayoutAnimationController 實(shí)例,調(diào)用 setOrder(int order) 方法無效!
評(píng)論
圖片
表情
