在android開(kāi)發(fā)中,編碼人員要考慮到每個(gè)模塊的構(gòu)建和維護(hù),當(dāng)然動(dòng)畫制作作為編碼人員的作品,下面是武林技術(shù)頻道為大家介紹的詳解Android開(kāi)發(fā)之圖形圖像與動(dòng)畫,一起來(lái)看看吧!
首先需要先介紹下LayoutAnimationController:
?* 1.LayoutAnimationController用于為一個(gè)layout里面的控件,或者是一個(gè)ViewGroup
?* 里面的控件設(shè)置動(dòng)畫效果(即整個(gè)布局)
?* 2.每一個(gè)控件都有相同的動(dòng)畫效果
?* 3.這些控件的動(dòng)畫效果在不同的實(shí)現(xiàn)顯示出來(lái)
?* 4.LayoutAnimationController可以在xml文件當(dāng)中設(shè)置,也可以在代碼中進(jìn)行設(shè)置
本文就針對(duì)兩種實(shí)現(xiàn)LayoutAnimationController的方法分別進(jìn)行介紹:
一,在XML文件中實(shí)現(xiàn)
步驟如下圖所示:

?下面以一個(gè)實(shí)例來(lái)說(shuō)明實(shí)現(xiàn)的方法:
實(shí)現(xiàn)的例子是點(diǎn)擊“測(cè)試”按鈕,有動(dòng)畫形式的view展現(xiàn)出來(lái),截圖如下:

具體的實(shí)現(xiàn)過(guò)程如下:
需要兩個(gè)動(dòng)畫xml文件:
1.list_item_layout
?
<layoutAnimation xmlns:android="http://schemas.android.com/apk/res/android"
android:animation="@anim/list_item_alpha"
android:animationOrder="normal"
android:delay="0.8" />
2.list_item_alpha
?
?
?
<set xmlns:android="http://schemas.android.com/apk/res/android">
<alpha
android:fromAlpha="0.0"
android:toAlpha="1.0"
android:duration="2000"
/>
</set>
3.需要在listview中添加如下的說(shuō)明:
?
?
?
android:layoutAnimation="@anim/list_item_layout"
具體的實(shí)現(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<String> adapter=new ArrayAdapter<String>(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代碼中實(shí)現(xiàn)LayoutAnimationController
?
實(shí)現(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);
上文是詳解Android開(kāi)發(fā)之圖形圖像與動(dòng)畫的介紹,武林技術(shù)頻道小編為大家做了簡(jiǎn)單的介紹。其實(shí)不管學(xué)習(xí)什么都要努力,努力后肯定有收獲。