android添加动画文件,Android开发之图形图像与动画(五)LayoutAnimationController详解
首先需要先介紹下LayoutAnimationController:
* 1.LayoutAnimationController用于為一個layout里面的控件,或者是一個ViewGroup
* 里面的控件設(shè)置動畫效果(即整個布局)
* 2.每一個控件都有相同的動畫效果
* 3.這些控件的動畫效果在不同的實現(xiàn)顯示出來
* 4.LayoutAnimationController可以在xml文件當(dāng)中設(shè)置,也可以在代碼中進(jìn)行設(shè)置
本文就針對兩種實現(xiàn)LayoutAnimationController的方法分別進(jìn)行介紹:
一,在XML文件中實現(xiàn)
步驟如下圖所示:
下面以一個實例來說明實現(xiàn)的方法:
實現(xiàn)的例子是點擊“測試”按鈕,有動畫形式的view展現(xiàn)出來,截圖如下:
具體的實現(xiàn)過程如下:
需要兩個動畫xml文件:
1.list_item_layout
android:animation="@anim/list_item_alpha"
android:animationOrder="normal"
android:delay="0.8" />
2.list_item_alpha
android:fromAlpha="0.0"
android:toAlpha="1.0"
android:duration="2000"
/>
3.需要在listview中添加如下的說明:
android:layoutAnimation="@anim/list_item_layout"
具體的實現(xiàn)代碼如下:
public class LayoutAnimation_Activity extends Activity {
private Button button;
private Button button2;
private ListView listView;
private static final String[] STRINGS={"BruceZhang","Alhpa","Translate","Blanklin","Rotate",
"GreenFrank"};
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_layout_animation_);
button=(Button)findViewById(R.id.button);
button2=(Button)findViewById(R.id.button2);
listView=(ListView)findViewById(R.id.listview);
final ArrayAdapter adapter=new ArrayAdapter(this, R.layout.item_list, STRINGS);
button.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
// TODO Auto-generated method stub
listView.setAdapter(adapter);
}
});
button2.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
// TODO Auto-generated method stub
listView.setAdapter(null);
}
});
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.activity_layout_animation_, menu);
return true;
}
}
二,在java代碼中實現(xiàn)LayoutAnimationController
實現(xiàn)的步驟如下圖:
在本例中用到的代碼如下:
Animation animation=AnimationUtils.loadAnimation(LayoutAnimation_Activity.this,
R.anim.list_item_alpha);
LayoutAnimationController laController=new LayoutAnimationController(animation);
laController.setOrder(LayoutAnimationController.ORDER_NORMAL);
listView.setLayoutAnimation(laController);
總結(jié)
以上是生活随笔為你收集整理的android添加动画文件,Android开发之图形图像与动画(五)LayoutAnimationController详解的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 上市公司发行股票数量是怎样决定的
- 下一篇: 最低工资标准包含哪些