簡(jiǎn)介
所謂的布局動(dòng)畫就是在
ViewGroup中添加子View的時(shí)候有一個(gè)過度的動(dòng)態(tài)效果.
使用方法
- 實(shí)現(xiàn)最簡(jiǎn)單的動(dòng)畫效果只要在xml布局文件中對(duì)ViewGroup開啟一個(gè)屬性:
android:animateLayoutChanges="true" - 此外還能通過
LayoutAnimationController其修改其默認(rèn)的動(dòng)畫:
例子
//已知container為某個(gè)ViewGroup
ScaleAnimation sa = new ScaleAnimation(0, 1, 0, 1, ScaleAnimation.RELATIVE_TO_SELF, 0.5f,
ScaleAnimation.RELATIVE_TO_SELF, 0.5f);
sa.setDuration(1000);
LayoutAnimationController lac = new LayoutAnimationController(sa);
container.setLayoutAnimation(lac);
View view = new View(AnimatorActivity.this);
LayoutParams lp = new LayoutParams(300, 300);
view.setLayoutParams(lp);
view.setBackgroundColor(Color.parseColor("#ffeebb"));
container.addView(view);
上面的代碼就是使添加View的時(shí)候子View通過中心放大的形式出現(xiàn)