Android动画之补间动画(XML 形式),电子版已问世

anim_rotate.xml

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

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

android:duration=“3000”

android:fillAfter=“true”>

<rotate

android:fromDegrees=“0”

android:toDegrees=“200”

android:pivotX=“50%”

android:pivotY=“50%”>

anim_scale.xml

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

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

android:duration=“3000”

android:fillAfter=“true”>

<scale

android:fromXScale=“1”

android:fromYScale=“1”

android:toXScale=“3”

android:toYScale=“3”

android:pivotY=“50%”

android:pivotX=“50%”>

anim_group.xml

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

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

android:duration=“3000”

android:fillAfter=“true”

<alpha

android:fromAlpha=“1”

android:toAlpha=“0.5”>

<scale

android:fromXScale=“1”

android:fromYScale=“1”

android:toXScale=“3”

android:toYScale=“3”

android:pivotY=“50%”

android:pivotX=“50%”>

FourActivity.java

public class FourActivity 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;

Animation animation;

@Override

protected void onCreate(Bundle savedInstanceState) {

super.onCreate(savedInstanceState);

setContentView(R.layout.activity_four);

initView();

}

private void initView() {

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

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

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

switch (v.getId()) {

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

//如果要用静态的动画(xml),就得用这个API

animation = AnimationUtils.loadAnimation(this, R.anim.anim_alpha);

break;

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

animation = AnimationUtils.loadAnimation(this, R.anim.anim_translate);

break;

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

animation = AnimationUtils.loadAnimation(this, R.anim.anim_rotate);

break;

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

animation = AnimationUtils.loadAnimation(this, R.anim.anim_scale);

break;

}

iv_show.startAnimation(animation);

}

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

animation = AnimationUtils.loadAnimation(this, R.anim.anim_group);

iv_show.startAnimation(animation);

}

}

activity_four.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=".FourActivity">

<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”
eight=“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”

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值