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

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

Android開發(fā)之nimationListener的簡(jiǎn)介

2020-02-21 17:30:34
字體:
來(lái)源:轉(zhuǎn)載
供稿:網(wǎng)友

就像按鈕控件有監(jiān)聽器一樣,動(dòng)畫效果也有監(jiān)聽器。動(dòng)畫偵聽器可用于監(jiān)視動(dòng)畫效果。有三個(gè)函數(shù)需要重載,下面就讓武林技術(shù)頻道小編帶大家來(lái)了解Android開發(fā)之nimationListener的簡(jiǎn)介吧!

?

private class MyListenr implements AnimationListener{
@Override
public void onAnimationEnd(Animation arg0) {
// TODO Auto-generated method stub
}
@Override
public void onAnimationRepeat(Animation arg0) {
// TODO Auto-generated method stub
}
@Override
public void onAnimationStart(Animation arg0) {
// TODO Auto-generated method stub
}

}


其中第一個(gè)函數(shù)的意思是在動(dòng)畫執(zhí)行完之后需要開發(fā)者做什么,第二個(gè)函數(shù)的意思是在動(dòng)畫重復(fù)執(zhí)行的過程中應(yīng)該做什么,第三個(gè)函數(shù)的意思是當(dāng)動(dòng)畫開始執(zhí)行時(shí)有什么動(dòng)作發(fā)生。

下面我實(shí)現(xiàn)了一個(gè)例子,點(diǎn)擊刪除按鈕,圖片慢慢淡去,并最終刪除,當(dāng)點(diǎn)擊添加按鈕時(shí)向viewGroup中添加一個(gè)imageview,實(shí)現(xiàn)的截圖如下:
?
具體的實(shí)現(xiàn)代碼如下:

?

?

?


public class MainActivity extends Activity {
private Button button;
private Button button2;
private ImageView imageView;
private ViewGroup viewGroup;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
button=(Button)findViewById(R.id.button_add);
button2=(Button)findViewById(R.id.button_delete);
imageView=(ImageView)findViewById(R.id.imageView1);
viewGroup=(ViewGroup)findViewById(R.id.viewGroup);
button.setOnClickListener(new Mybutton());
button2.setOnClickListener(new Mybutton());
}
private class Mybutton implements OnClickListener{
@Override
public void onClick(View v) {
// TODO Auto-generated method stub
switch (v.getId()) {
case R.id.button_add:
Add();
break;
case R.id.button_delete:
Delete();
break;
default:
break;
}
}
}

public void Add() {
AlphaAnimation alphaAnimation=new AlphaAnimation(0.0f, 1.0f);
alphaAnimation.setDuration(2000);
alphaAnimation.setStartOffset(500);
ImageView imageViewAdd=new ImageView(MainActivity.this);
imageViewAdd.setImageResource(R.drawable.ic_launcher);
viewGroup.addView(imageViewAdd);
// viewGroup.addView(imageViewAdd, new LayoutParams(
// LayoutParams.WRAP_CONTENT,LayoutParams.WRAP_CONTENT));
imageViewAdd.startAnimation(alphaAnimation);
}
public void Delete() {
AlphaAnimation alphaAnimation=new AlphaAnimation(1.0f, 0.0f);
alphaAnimation.setDuration(2000);
alphaAnimation.setStartOffset(500);
imageView.startAnimation(alphaAnimation);
alphaAnimation.setAnimationListener(new MyListenr());
}

private class MyListenr implements AnimationListener{
@Override
public void onAnimationEnd(Animation arg0) {
// TODO Auto-generated method stub
viewGroup.removeView(imageView);
Log.d("BruceZhang", "Animation End!");
}
@Override
public void onAnimationRepeat(Animation arg0) {
// TODO Auto-generated method stub
Log.d("BruceZhang", "Animation Repeat!");
}
@Override
public void onAnimationStart(Animation arg0) {
// TODO Auto-generated method stub
Log.d("BruceZhang", "Animation Start!");
}

}
@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_main, menu);
return true;
}
}


此實(shí)例的布局文件如下,注意,需要在根標(biāo)簽下給出viewGroup的id:

?

?

?


<AbsoluteLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".MainActivity"
android:id="@+id/viewGroup"
>
<Button
android:id="@+id/button_add"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_x="0dp"
android:layout_y="367dp"
android:text="添加圖片" />
<Button
android:id="@+id/button_delete"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_x="0dp"
android:layout_y="410dp"
android:text="刪除圖片" />
<ImageView
android:id="@+id/imageView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_x="153dp"
android:layout_y="155dp"
android:src="@drawable/ic_launcher" />
</AbsoluteLayout>

?以上就是武林技術(shù)頻道小編為大家?guī)?lái)的Android開發(fā)之nimationListener的簡(jiǎn)介,看了以上的攻略后,對(duì)你學(xué)習(xí)有沒有幫助呢?

發(fā)表評(píng)論 共有條評(píng)論
用戶名: 密碼:
驗(yàn)證碼: 匿名發(fā)表
主站蜘蛛池模板: 信丰县| 称多县| 达拉特旗| 鄂温| 乐昌市| 轮台县| 黔东| 汶川县| 杭锦后旗| 合作市| 会同县| 新巴尔虎左旗| 西贡区| 临沂市| 呈贡县| 赤城县| 兴业县| 工布江达县| 长垣县| 纳雍县| 额济纳旗| 准格尔旗| 达拉特旗| 贵州省| 甘孜县| 上杭县| 来凤县| 六安市| 元朗区| 高密市| 达尔| 湖口县| 冀州市| 九江县| 三明市| 上饶市| 楚雄市| 明溪县| 琼海市| 桐庐县| 曲靖市|