国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 系統(tǒng) > Android > 正文

Android開發(fā)之圖形圖像與動畫(五)LayoutAnimationController詳解

2020-04-11 12:32:06
字體:
來源:轉載
供稿:網(wǎng)友

  首先需要先介紹下LayoutAnimationController:

 * 1.LayoutAnimationController用于為一個layout里面的控件,或者是一個ViewGroup
 * 里面的控件設置動畫效果(即整個布局)
 * 2.每一個控件都有相同的動畫效果
 * 3.這些控件的動畫效果在不同的實現(xiàn)顯示出來
 * 4.LayoutAnimationController可以在xml文件當中設置,也可以在代碼中進行設置

本文就針對兩種實現(xiàn)LayoutAnimationController的方法分別進行介紹:

一,在XML文件中實現(xiàn)

步驟如下圖所示:



 下面以一個實例來說明實現(xiàn)的方法

實現(xiàn)的例子是點擊“測試”按鈕,有動畫形式的view展現(xiàn)出來,截圖如下:


具體的實現(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"

具體的實現(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代碼中實現(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);

發(fā)表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發(fā)表
主站蜘蛛池模板: 寿阳县| 阿拉善盟| 乡城县| 韩城市| 建水县| 禹州市| 惠州市| 游戏| 米易县| 梅河口市| 绵阳市| 曲麻莱县| 建湖县| 定边县| 江门市| 麻城市| 湘阴县| 阳江市| 安阳县| 文登市| 启东市| 略阳县| 富顺县| 秀山| 隆昌县| 新昌县| 会东县| 图们市| 阿拉尔市| 镇巴县| 磐安县| 古丈县| 林芝县| 离岛区| 柏乡县| 温宿县| 贵港市| 滕州市| 汶上县| 基隆市| 桓台县|