Android动画之属性动画,阿里巴巴开发规范手册

android:layout_height=“wrap_content”

android:layout_centerInParent=“true”

android:src="@mipmap/ic_launcher" />

<Button

android:layout_width=“match_parent”

android:layout_height=“wrap_content”

android:layout_alignParentBottom=“true”

android:onClick=“groupshow”

android:text=“组合显示” />

ThirdActivity.java文件:

//属性动画

public class ThirdActivity extends AppCompatActivity implements View.OnClickListener {

《Android学习笔记总结+最新移动架构视频+大厂安卓面试真题+项目实战源码讲义》

【docs.qq.com/doc/DSkNLaERkbnFoS0ZF】 完整内容开源分享

private Button btn_alpha;

private Button btn_translate;

private Button btn_rotate;

private Button btn_scale;

private ImageView iv_show;

ObjectAnimator objectAnimator;

@Override

protected void onCreate(Bundle savedInstanceState) {

super.onCreate(savedInstanceState);

setContentView(R.layout.activity_third);

initView();

}

private void initView() {

btn_alpha = (Button) findViewById(R.id.btn_alpha);

btn_translate = (Button) findViewById(R.id.btn_translate);

btn_rotate = (Button) findViewById(R.id.btn_rotate);

btn_scale = (Button) findViewById(R.id.btn_scale);

iv_show = (ImageView) findViewById(R.id.iv_show);

btn_alpha.setOnClickListener(this);

btn_translate.setOnClickListener(this);

btn_rotate.setOnClickListener(this);

btn_scale.setOnClickListener(this);

}

@Override

public void onClick(View v) {

//ofFloat:三个参数 :1.受到动画影响的对象(UI控件)2. 要执行的动画类型 3. 一组动画的属性

switch (v.getId()) {

case R.id.btn_alpha://透明动画

objectAnimator = ObjectAnimator.ofFloat(iv_show, “alpha”, 0.5f, 1f, 0.5f, 1f);

break;

case R.id.btn_translate://位移动画

//只会执行一个

objectAnimator = ObjectAnimator.ofFloat(iv_show, “translationX”, 0, 200);

//objectAnimator=ObjectAnimator.ofFloat(iv_show,“translationY”,0,200);

break;

case R.id.btn_rotate://旋转动画

objectAnimator = ObjectAnimator.ofFloat(iv_show, “rotation”, 0, 90f, 180f, 90f, 45f, 100f);

break;

case R.id.btn_scale://缩放动画

//只会执行一个

objectAnimator = ObjectAnimator.ofFloat(iv_show, “scaleY”, 1f, 2f, 3f, 4f);

// objectAnimator=ObjectAnimator.ofFloat(iv_show,“scaleX”,1f,2f,3f,4f);

break;

}

//动画持续时间

objectAnimator.setDuration(3000);

//启动动画

objectAnimator.start();

}

public void groupshow(View view) {//组合

ObjectAnimator objectAnimator1 = ObjectAnimator.ofFloat(iv_show, “scaleY”, 1f, 2f, 1f, 2f);

ObjectAnimator objectAnimator2 = ObjectAnimator.ofFloat(iv_show, “scaleX”, 1f, 2f, 1f, 2f);

ObjectAnimator objectAnimator3 = ObjectAnimator.ofFloat(iv_show, “rotation”, 0, 90f, 180f, 90f, 45f, 100f);

//创建属性动画的集合容器

AnimatorSet animatorSet = new AnimatorSet();

//同时播放

animatorSet.play(objectAnimator1).with(objectAnimator2).with(objectAnimator3);

//按照顺序播放

// animatorSet.play(objectAnimator1).after(objectAnimator2).after(objectAnimator3);

/*

  • 另一种方式

List list=new ArrayList<>();

list.add(objectAnimator1);

list.add(objectAnimator2);

list.add(objectAnimator3);

animatorSet.playSequentially(list);//按照顺序播放

animatorSet.playTogether(list);//同时执行

*/

//设置时长

animatorSet.setDuration(3000);

//启动

animatorSet.start();

}

上一篇:买卖股票的最佳时机 IV ——动态规划-股票收益问题


下一篇:Ubuntu 18.04 安装 Cuda 8.0+cuDNN v5.1