应用场景,View出场逐渐由小到大显示,View退出逐渐由大到小的效果:

代码:

Activity部分:

package com.lenovo.dh.zuidemo.ui.activity;import android.animation.ObjectAnimator;import android.os.Bundle;import android.view.View;import android.view.animation.Animation;import android.view.animation.AnimationUtils;import android.widget.Button;import android.widget.ImageView;import androidx.annotation.Nullable;import androidx.appcompat.app.AppCompatActivity;import com.lenovo.dh.zuidemo.R;public class AnimatorActivity extends AppCompatActivity {    private Button btAnimator,btAnimatorStop;    private ImageView img;    @Override    protected void onCreate(@Nullable Bundle savedInstanceState) {        super.onCreate(savedInstanceState);        setContentView(R.layout.zui_animator);        btAnimator = (Button)findViewById(R.id.btAnimator);        btAnimatorStop = (Button)findViewById(R.id.btAnimatorStop);        img = (ImageView)findViewById(R.id.img);        btAnimator.setOnClickListener(new View.OnClickListener() {            @Override            public void onClick(View v) {                //逐渐消失动画                img.setImageResource(R.mipmap.ic_launcher);                ObjectAnimator animator = ObjectAnimator.ofInt(new WrapView(img),"width",10);                animator.setDuration(10000);                //animator.setRepeatCount(1); //动画重复的次数                animator.start();            }        });        btAnimatorStop.setOnClickListener(new View.OnClickListener() {            @Override            public void onClick(View v) {                //逐渐出现动画                img.setImageResource(R.mipmap.ic_launcher);                Animation animation = AnimationUtils.loadAnimation(getApplicationContext(),R.anim.enlarge);                animation.setFillAfter(true);                img.startAnimation(animation);            }        });    }    class WrapView{        private View view;        private int width;        private int height;        public WrapView(View view){            this.view = view;        }        public int getWidth(){            return view.getLayoutParams().width;        }        public void setWidth(int width){            this.width = width;            view.getLayoutParams().width = width;            view.requestLayout();        }        public int getHeight(){            return view.getLayoutParams().height;        }        public void setHeight(){            this.height = height;            view.getLayoutParams().height = height;            view.requestLayout();        }    }}

layout部分:

zui_animator.xml

<?xml version="1.0" encoding="utf-8"?>    

 

res/anim部分:

enlarge.xml

<?xml version="1.0" encoding="utf-8"?>      

(由于受限,无法上传效果视频)

 

更多相关文章

  1. Android 动画的重复播放
  2. Android使用TextView实现跑马灯效果
  3. Android之屏幕切换使用技巧
  4. Android 中屏幕点击事件的实现
  5. Android 禁止响应屏幕翻转
  6. TextView属性android:ellipsize实现跑马灯效果
  7. Android动画设置interpolator插值器
  8. 与屏幕有关的设置:禁止横竖屏切换;横竖屏切换不重启Activity;动态设
  9. [记录]Android虚拟机大屏幕设置

随机推荐

  1. 什么?Android上面跑Linux?
  2. 仿php中文网演练
  3. 2021年Android进阶者的新篇章,成功拿下大
  4. Android-Handler的消息传递机制
  5. 简洁、高效、可自定义的开源的Android评
  6. Android(安卓)动画之Lottie动画使用
  7. Android(安卓)动画之Lottie动画使用
  8. Android中的线程模型
  9. Android实现布局全屏
  10. 源码中的@hide注释和{@hide}注释的差异