一、代码

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. css position 定位

    fixed 属于绝对定位,相对于浏览器窗口定位 (IE 6不支持)   relative 相对定位,通过设置垂直或水平位置,让这个元素"相对于"它的原始起点进行移动.       ...

  2. 在HTML中怎么去掉a标签(超链接)的下划线?

    <style type="text/css">a:link,a:visited{ text-decoration:none; /*超链接无下划线*/}a:hover{ ...

  3. Jquery Ajax 调用 WebService

    原文:http://www.cnblogs.com/andiki/archive/2010/05/17/1737254.html jquery ajax调用webservice(C#)要注意的几个事项 ...

  4. RAC分解步骤之一,在oracle linux 4u4上安装oracle 10.2.0.1.0操作日志

    练习oracle的rac组建过程,第一步,先练习4u4上安装oracle 10.2.0.1.0.直接安装rac,有些难度.从简单的做起.总RAC步骤,参照小布老师的RAC组建. 1. 启动vc,登陆v ...

  5. selenium IDE处理各种窗口问题解决方法

    一.处理模态窗口:showModalDialog 由于弹出模态窗口后,就无法定位到当前窗口的元素和模态窗口的元素,需要添加js解决 模态窗口动作类似下面语句: <input id="c ...

  6. java新手笔记7 找最小、最大、排序

    1.最小数 // 1.0 public class SortDemo1 { public static void main(String[] args) { int[] a = {2,5,4,6,8, ...

  7. ubuntu下怎么合并windows下分割的zip包

    cat ziptest.z* > google_bak.zip 点击打开链接http://blog.51yip.com/linux/988.html

  8. fork();

    僵死进程: 父进程没有等待子进程,wait() 子进程会变成僵死进程. int main(int arg, char *args[]){ pid_t pid = fork();//调用fork产生一个 ...

  9. jquery 中的 $("#id") 与 document.getElementById("id") 的区别

    以前没注意过,认为jquery 中的 $("#air") 与 document.getElementById("air") 是一回事,指的是同一个东西.在今天写 ...

  10. Quartz 之 windowService

    (一)创建服务 QuarzService using System.ServiceProcess;using System.Text; using Quartz;using Quartz.Impl; ...