Android动画之属性动画,android开发网易新闻

1.透明动画:alpha

2.位移动画:translationX,translationY

3.旋转动画:rotation

4.缩放动画:scaleX,scaleY

5.组合显示:AnimatorSet(动画集合容器)

1.透明动画:alpha在这里插入图片描述

2.位移动画:translationX,translationY

![在这里插入图片描述](https://img-blog.csdnimg.cn/20190808144950607.png?x-oss-process=image/watermark,type_ZmFuZ3poZW5naGVpdGk,shadow_10,text_aHR0c

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

开源分享完整内容戳这里

HM6Ly9ibG9nLmNzZG4ubmV0L3FxXzQyNzYxMzk1,size_16,color_FFFFFF,t_70)

3.旋转动画:rotation

在这里插入图片描述

4…缩放动画:scaleX,scaleY

在这里插入图片描述

5.组合显示:AnimatorSet(动画集合容器)在这里插入图片描述

源码如下:

activity_third.xml文件:

<RelativeLayout xmlns:android=“http://schemas.android.com/apk/res/android”

xmlns:app=“http://schemas.android.com/apk/res-auto”

xmlns:tools=“http://schemas.android.com/tools”

android:layout_width=“match_parent”

android:layout_height=“match_parent”

tools:context=".ThirdActivity">

<LinearLayout

android:layout_width=“match_parent”

android:layout_height=“wrap_content”

android:orientation=“horizontal”>

<Button

android:id="@+id/btn_alpha"

android:layout_width=“0dp”

android:layout_height=“40dp”

android:layout_weight=“1”

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

<Button

android:id="@+id/btn_translate"

android:layout_width=“0dp”

android:layout_height=“40dp”

android:layout_weight=“1”

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

<Button

android:id="@+id/btn_rotate"

android:layout_width=“0dp”

android:layout_height=“40dp”

android:layout_weight=“1”

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

<Button

android:id="@+id/btn_scale"

android:layout_width=“0dp”

android:layout_height=“40dp”

android:layout_weight=“1”

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

<ImageView

android:id="@+id/iv_show"

android:layout_width=“wrap_content”

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 {

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;

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值