栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 软件开发 > 后端开发 > Java

Android动画之属性动画

Java 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

Android动画之属性动画

android:layout_width=“match_parent”

android:layout_height=“wrap_content”

android:orientation=“horizontal”>

android:id="@+id/btn_alpha"

android:layout_width=“0dp”

android:layout_height=“40dp”

android:layout_weight=“1”

android:text=“透明动画” />

android:id="@+id/btn_translate"

android:layout_width=“0dp”

android:layout_height=“40dp”

android:layout_weight=“1”

android:text=“位移动画” />

android:id="@+id/btn_rotate"

android:layout_width=“0dp”

android:layout_height=“40dp”

android:layout_weight=“1”

android:text=“旋转动画” />

android:id="@+id/btn_scale"

android:layout_width=“0dp”

android:layout_height=“40dp”

android:layout_weight=“1”

android:text=“缩放动画” />

android:id="@+id/iv_show"

android:layout_width=“wrap_content”

android:layout_height=“wrap_content”

android:layout_centerInParent=“true”

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

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 {

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);

转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/531354.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号