Q群: 241359063 更精彩,欢迎共同走向创业学习之旅。
原创:kylin_zeng http://blog.chinaunix.net/uid/23795897.html在此感谢mars 老师的帮助。转载请注明原创出处,尊重他人的劳动成果。
1、animationListener 监听器,它是在动画执行的各个阶段会得到通知,从而调用相应的方法:
1.1 onAnimationEnd(Animation animation) //动画执行结束
1.2 onAnimationRepeat(Animation animation) //动画重新执行
1.3 onAnimationStart(Animation animation) //动画开始
2、例如:
17_animations07.rar
阅读(122) | 评论(0) | 转发(0) |
<script>window._bd_share_config={"common":{"bdSnsKey":{},"bdText":"","bdMini":"2","bdMiniList":false,"bdPic":"","bdStyle":"0","bdSize":"16"},"share":{}};with(document)0[(getElementsByTagName('head')[0]||body).appendChild(createElement('script')).src='http://bdimg.share.baidu.com/static/api/js/share.js?v=89860593.js?cdnversion='+~(-new Date()/36e5)];</script>
原创:kylin_zeng http://blog.chinaunix.net/uid/23795897.html在此感谢mars 老师的帮助。转载请注明原创出处,尊重他人的劳动成果。
1、animationListener 监听器,它是在动画执行的各个阶段会得到通知,从而调用相应的方法:
1.1 onAnimationEnd(Animation animation) //动画执行结束
1.2 onAnimationRepeat(Animation animation) //动画重新执行
1.3 onAnimationStart(Animation animation) //动画开始
2、例如:
点击(此处)折叠或打开
- package mars.animation07;
-
- import android.app.Activity;
- import android.os.Bundle;
- import android.view.View;
- import android.view.ViewGroup;
- import android.view.View.OnClickListener;
- 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 {
- /** Called when the activity is first created. */
- private Button removeButton = null;
- private Button addButton = null;
- private ImageView imageView = null;
- private ViewGroup viewGroup = null;
- @Override
- public void onCreate(Bundle savedInstanceState) {
- super.onCreate(savedInstanceState);
- setContentView(R.layout.main);
- removeButton = (Button)findViewById(R.id.removeButtonId);
- imageView = (ImageView)findViewById(R.id.imageViewId);
- removeButton.setOnClickListener(new RemoveButtonListener());
- viewGroup = (ViewGroup)findViewById(R.id.layoutId);
- addButton = (Button)findViewById(R.id.addButtonId);
- addButton.setOnClickListener(new AddButtonListener());
- }
- private class AddButtonListener implements OnClickListener{
- @Override
- public void onClick(View v) {
- //创建了一个淡入效果的Animation对象
- AlphaAnimation animation = new AlphaAnimation(0.0f,1.0f);
- animation.setDuration(1000);
- animation.setStartOffset(500);
- //创建一个新的ImageView
- ImageView imageViewAdd = new ImageView(MainActivity.this);
- imageViewAdd.setImageResource(R.drawable.icon);
- //将新的ImageView添加到viewGroup当中
- viewGroup.addView(imageViewAdd, new LayoutParams(LayoutParams.FILL_PARENT, LayoutParams.WRAP_CONTENT));
- //启动动画
- imageViewAdd.startAnimation(animation);
- }
-
- }
-
- private class RemoveButtonListener implements OnClickListener{
-
- @Override
- public void onClick(View v) {
- //创建一个淡出效果的Animation对象
- AlphaAnimation animation = new AlphaAnimation(1.0f,0.0f);
- //为Animation对象设置属性
- animation.setDuration(1000);
- animation.setStartOffset(500);
- //为Animation对象设置监听器
- animation.setAnimationListener(new RemoveAnimationListener());
- imageView.startAnimation(animation);
- }
- }
-
- private class RemoveAnimationListener implements AnimationListener{
- //该方法在淡出效果执行结束之后被调用
- @Override
- public void onAnimationEnd(Animation animation) {
- System.out.println("end");
- //从viewGroup当中删除掉imageView控件
- viewGroup.removeView(imageView);
- }
-
- @Override
- public void onAnimationRepeat(Animation animation) {
- System.out.println("repeat");
- }
-
- @Override
- public void onAnimationStart(Animation animation) {
- System.out.println("start");
- }
-
- }
- }

相关热门文章
给主人留下些什么吧!~~
评论热议