一、代码

1.xml
(1)activity_main.xml

 <?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/layoutId"
android:orientation="vertical" android:layout_width="fill_parent"
android:layout_height="fill_parent">
<Button android:id="@+id/addButtonId" android:layout_width="fill_parent"
android:layout_height="wrap_content" android:layout_alignParentBottom="true"
android:text="添加图片" /> <Button android:id="@+id/removeButtonId" android:layout_width="fill_parent"
android:layout_height="wrap_content" android:layout_above="@id/addButtonId"
android:text="删除图片" /> <ImageView android:id="@+id/imageViewId"
android:layout_width="wrap_content" android:layout_height="wrap_content"
android:layout_centerInParent="true" android:layout_marginTop="100dip"
android:src="@drawable/a1" />
</RelativeLayout>

2.java
(1)MainActivity.java

 package com.animationlistener;

 import android.app.Activity;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.ViewGroup;
import android.view.ViewGroup.LayoutParams;
import android.view.animation.AlphaAnimation;
import android.view.animation.Animation;
import android.view.animation.Animation.AnimationListener;
import android.widget.Button;
import android.widget.ImageView; public class MainActivity extends Activity { private Button removeButton = null;
private Button addButton = null;
private ImageView imageView = null;
private ViewGroup viewGroup = null; @Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main); removeButton = (Button)findViewById(R.id.removeButtonId);
removeButton.setOnClickListener(new RemoveButtonListener());
addButton = (Button)findViewById(R.id.addButtonId);
addButton.setOnClickListener(new AddButtonListener()); imageView = (ImageView)findViewById(R.id.imageViewId);
viewGroup = (ViewGroup) findViewById(R.id.layoutId);
} class AddButtonListener implements OnClickListener {
@Override
public void onClick(View v) {
Animation animation = new AlphaAnimation(0.0f, 1.0f);
animation.setDuration(1000);
animation.setStartOffset(500);
ImageView imageViewAdd = new ImageView(MainActivity.this);
imageViewAdd.setImageResource(R.drawable.a1);
viewGroup.addView(imageViewAdd, new LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.WRAP_CONTENT));
imageViewAdd.startAnimation(animation);
}
} class RemoveButtonListener implements OnClickListener {
@Override
public void onClick(View v) {
Animation animation = new AlphaAnimation(1.0f, 0.0f);
animation.setDuration(1000);
animation.setStartOffset(500);
animation.setAnimationListener(new RemoveAnimationListener());
imageView.startAnimation(animation);
}
} class RemoveAnimationListener implements AnimationListener { @Override
public void onAnimationStart(Animation animation) {
System.out.println("Start");
} @Override
public void onAnimationEnd(Animation animation) {
System.out.println("End");
viewGroup.removeView(imageView);
} @Override
public void onAnimationRepeat(Animation animation) {
System.out.println("Repeat");
}
}
}

ANDROID_MARS学习笔记_S02_012_ANIMATION_利用AnimationListener在动画结束时删除或添加组件的更多相关文章

  1. ANDROID_MARS学习笔记_S04_007_从服务器获取微博数据时间线

    一.代码 1.xml(1)activity_main.xml <?xml version="1.0" encoding="utf-8"?> < ...

  2. 学习笔记:利用GDI+生成简单的验证码图片

    学习笔记:利用GDI+生成简单的验证码图片 /// <summary> /// 单击图片时切换图片 /// </summary> /// <param name=&quo ...

  3. 机器学习实战(Machine Learning in Action)学习笔记————09.利用PCA简化数据

    机器学习实战(Machine Learning in Action)学习笔记————09.利用PCA简化数据 关键字:PCA.主成分分析.降维作者:米仓山下时间:2018-11-15机器学习实战(Ma ...

  4. Spring MVC 学习笔记2 - 利用Spring Tool Suite创建一个web 项目

    Spring MVC 学习笔记2 - 利用Spring Tool Suite创建一个web 项目 Spring Tool Suite 是一个带有全套的Spring相关支持功能的Eclipse插件包. ...

  5. React Native 学习笔记--进阶(二)--动画

    React Native 进阶(二)–动画 动画 流畅.有意义的动画对于移动应用用户体验来说是非常必要的.我们可以联合使用两个互补的系统:用于全局的布局动画LayoutAnimation,和用于创建更 ...

  6. transitionend事件 监听 fadeIn fadeOut 两个方法无效(动画结束时无法执行transitionend里面的代码)

    //下面的例子证明 fadeIn() fadeOut() 不能使用transitionend事件进行监听. //说白了在fadeIn fadeOut 后面监听动画结束时,transitionend是不 ...

  7. Django学习笔记(13)——Django的用户认证(Auth)组件,视图层和QuerySet API

    用户认证组件的学习 用户认证是通过取表单数据根数据库对应表存储的值做比对,比对成功就返回一个页面,不成功就重定向到登录页面.我们自己写的话当然也是可以的,只不过多写了几个视图,冗余代码多,当然我们也可 ...

  8. Tomcat负载均衡、调优核心应用进阶学习笔记(一):tomcat文件目录、页面、架构组件详解、tomcat运行方式、组件介绍、tomcat管理

    文章目录 tomcat文件目录 bin conf lib logs temp webapps work 页面 架构组件详解 tomcat运行方式 组件介绍 tomcat管理 tomcat文件目录 ➜ ...

  9. 【C语言编程学习笔记】利用462字节代码实现雅虎logo ACSII 动画!

    ACSII 动画演示:   不过本文介绍的是另一个作品:c 代码实现雅虎 logo ACSII 动图. 运行后,你将会看到:   它是一个 20fps.抗锯齿的 Yahoo! logo ASCII 动 ...

随机推荐

  1. 【转】性能测试设计和LR原理的探讨

    做了4个迭代的性能测试, 在没有需求的情况下步步艰辛,把代码和框架独立开发从0到一万多行代码的测试工具(脚本),作为性能测试工具佼佼者Lr,我时而拿他作参考,山寨了它很多 东西,同时带有很多疑问对它实 ...

  2. CF-gym-100523-C(水题)

    Will It Stop? Available memory: 64 MB. Byteasar was wandering around the library of the University o ...

  3. js读取Excel文件数据-IE浏览器

    <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN"> <html> <head ...

  4. linq to ef(相当于sql中in的用法)查询语句

    select * from DoctorInfo doctor where doctor.HosDepartId in (select Id from HospitalDepartment hd wh ...

  5. oracle linux下oracle 10g启动EM、isqlplus及相关命令语法

    转载:http://hancang2000.blog.sohu.com/139239421.html ORACLE_HOME/bin/emctl start dbconsole $ORACLE_HOM ...

  6. linux命令行执行db2存储过程

    存储过程代码如下: CREATE PROCEDURE proc_sum2(IN n INT,OUT sum INT,OUT j INT) BEGIN DECLARE i INT; ; ; ; WHIL ...

  7. http 请求头

    HTTP Request的Header信息 1.HTTP请求方式 如下表: GET 向Web服务器请求一个文件 POST 向Web服务器发送数据让Web服务器进行处理 PUT 向Web服务器发送数据并 ...

  8. RIME输入法

    RIME输入法 1.可以输入汉语拼音. (1) RIME内置的「地球拼音」可以在选择完字之后按下「Shift+Enter」键,直接输入汉语拼音,并且是带声调的. (2) 自己配置汉语拼音方案. 2.五 ...

  9. IOS 学习笔记 2015-03-20 OC-数值类型

    一 定义 在Objective-C中,我们可以使用c中的数字数据类型,int.float.long等.它们都是基本数据类型,而不是对象.也就是说,不能够向它们发送消息.然后,有些时候需要将这些值作为对 ...

  10. input file 模拟预览图片。

    首先申明,接下来内容只是单纯的预览图片,最多选择九张,并没有和后台交互,交互的话需要自己另外写js. 本来想写一个调用摄像头的demo,意外的发现input file 在手机端打开的话,ios可以调用 ...