Android開發(fā)之圖形圖像與動畫(五)LayoutAnimationController詳解
首先需要先介紹下LayoutAnimationController:
* 1.LayoutAnimationController用于為一個layout里面的控件,或者是一個ViewGroup
* 里面的控件設(shè)置動畫效果(即整個布局)
* 2.每一個控件都有相同的動畫效果
* 3.這些控件的動畫效果在不同的實(shí)現(xiàn)顯示出來
* 4.LayoutAnimationController可以在xml文件當(dāng)中設(shè)置,也可以在代碼中進(jìn)行設(shè)置
本文就針對兩種實(shí)現(xiàn)LayoutAnimationController的方法分別進(jìn)行介紹:
一,在XML文件中實(shí)現(xiàn)
步驟如下圖所示:
下面以一個實(shí)例來說明實(shí)現(xiàn)的方法:
實(shí)現(xiàn)的例子是點(diǎn)擊“測試”按鈕,有動畫形式的view展現(xiàn)出來,截圖如下:
具體的實(shí)現(xiàn)過程如下:
需要兩個動畫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中添加如下的說明:
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開發(fā)之圖形圖像與動畫(一)Paint和Canvas類學(xué)習(xí)
- Android開發(fā)之圖形圖像與動畫(二)Animation實(shí)現(xiàn)圖像的漸變/縮放/位移/旋轉(zhuǎn)
- Android開發(fā)之圖形圖像與動畫(三)Animation效果的XML實(shí)現(xiàn)
- Android開發(fā)之圖形圖像與動畫(四)AnimationListener簡介
- android中圖形圖像處理之drawable用法分析
- Android編程開發(fā)之在Canvas中利用Path繪制基本圖形(圓形,矩形,橢圓,三角形等)
- Android開發(fā) OpenGL ES繪制3D 圖形實(shí)例詳解
- Android編程之canvas繪制各種圖形(點(diǎn),直線,弧,圓,橢圓,文字,矩形,多邊形,曲線,圓角矩形)
- Android自定義View實(shí)現(xiàn)shape圖形繪制
- android繪制幾何圖形的實(shí)例代碼
相關(guān)文章
Android 判斷屏幕開關(guān)狀態(tài)方式總結(jié)
這篇文章主要介紹了Android 判斷屏幕開關(guān)狀態(tài)方式總結(jié)的相關(guān)資料,需要的朋友可以參考下2016-10-10Android中獲取sha1證書指紋數(shù)據(jù)的方法
大家都知道在Android開發(fā)中,經(jīng)常要獲取sha1證書指紋,所以這篇文章主要介紹在Android中如何使用命令獲取sha1證書指紋數(shù)據(jù)的方法,有需要的可以參考借鑒。2016-09-09Android微信搶紅包功能的實(shí)現(xiàn)原理淺析
快到新年了,微信紅包越來越多,那么基于程序是怎么實(shí)現(xiàn)的呢?今天小編給大家分享Android微信搶紅包功能的實(shí)現(xiàn)原理淺析,一起看看吧2017-01-01android獲取相冊圖片和路徑的實(shí)現(xiàn)方法
這篇文章主要介紹了android獲取相冊圖片和路徑的實(shí)現(xiàn)方法,本文介紹的是Android4.4后的方法,感興趣的小伙伴們可以參考一下2016-04-04android ListView和ProgressBar(進(jìn)度條控件)的使用方法
這篇文章主要介紹了android ListView控件的使用方法和ProgressBar(進(jìn)度條控件)的使用方法,代碼大家可以參考使用2013-11-11Android音視頻開發(fā)Media FrameWork框架源碼解析
這篇文章主要為大家介紹了Android音視頻開發(fā)Media FrameWork框架源碼解析,有需要的朋友可以借鑒參考下,希望能夠有所幫助,祝大家多多進(jìn)步,早日升職加薪2022-12-12超簡單Android集成華為HMS Scankit 掃碼SDK實(shí)現(xiàn)掃一掃二維碼
這篇文章主要介紹了超簡單Android集成華為HMS Scankit 掃碼SDK實(shí)現(xiàn)掃一掃二維碼,文中通過示例代碼介紹的非常詳細(xì),對大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來一起學(xué)習(xí)學(xué)習(xí)吧2020-03-03使用ListView實(shí)現(xiàn)網(wǎng)上訂餐首頁
這篇文章主要為大家詳細(xì)介紹了使用ListView實(shí)現(xiàn)網(wǎng)上訂餐首頁,文中示例代碼介紹的非常詳細(xì),具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下2021-01-01Android使用SmsManager實(shí)現(xiàn)短信發(fā)送功能
這篇文章主要為大家詳細(xì)介紹了Android使用SmsManager實(shí)現(xiàn)短信發(fā)送功能,具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下2017-11-11