Android笔记 xml补间动画

fromAlpha开始透明度 toAlpha结束透明度

fillAfter与fillBefore指定最终是与开始还是结束样式相同

android:pivotY="50%" 相对于自身 写成android:pivotY="50%p"则是相对于父容器


1res下新建anim文件夹(Animation缩写)

new 5个xml 文件名自定 类型 alpha rotae set等每个都建一个

alpha_anim.xml

<?xml version="1.0" encoding="utf-8"?>
<alpha xmlns:android="http://schemas.android.com/apk/res/android"
    android:duration="2000"
    android:fillAfter="true"
    android:fromAlpha="0.5"
    android:startOffset="1000"
    android:toAlpha="1.0" >

</alpha>

rotate_anim.xml

<?xml version="1.0" encoding="utf-8"?>
<rotate xmlns:android="http://schemas.android.com/apk/res/android"
    android:duration="2000"
    android:fromDegrees="0"
    android:pivotX="50%"
    android:pivotY="50%"
    android:toDegrees="360" >

</rotate>
scale_anim.xml

<?xml version="1.0" encoding="utf-8"?>
<scale xmlns:android="http://schemas.android.com/apk/res/android"
    android:duration="2000"
    android:fillAfter="true"
    android:fromXScale="0.2"
    android:fromYScale="0.2"
    android:toXScale="2.0"
    android:toYScale="2.0" >

</scale>
set_anim.xml

<?xml version="1.0" encoding="utf-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android" >

    <alpha
        android:duration="2000"
        android:fillAfter="true"
        android:fromAlpha="0.5"
        android:startOffset="1000"
        android:toAlpha="1.0" >
        <rotate
            android:duration="2000"
            android:fromDegrees="0"
            android:pivotX="50%"
            android:pivotY="50%"
            android:toDegrees="360" >
        </rotate>
    </alpha>

</set>
translate_anim.xml

<?xml version="1.0" encoding="utf-8"?>
<translate xmlns:android="http://schemas.android.com/apk/res/android"
    android:duration="2000"
    android:fromXDelta="20%p"
    android:fromYDelta="0"
    android:repeatCount="2"
    android:repeatMode="reverse"
    android:toXDelta="50%p"
    android:toYDelta="50%p" >

</translate>

2MainActivity

package com.example.a113xmlanimation;

import android.os.Bundle;
import android.app.Activity;
import android.view.View;
import android.view.animation.AlphaAnimation;
import android.view.animation.Animation;
import android.view.animation.AnimationSet;
import android.view.animation.AnimationUtils;
import android.view.animation.RotateAnimation;
import android.view.animation.ScaleAnimation;
import android.view.animation.TranslateAnimation;
import android.widget.ImageView;

public class MainActivity extends Activity {

	private ImageView iv;

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.activity_main);
		iv = (ImageView) findViewById(R.id.iv);
	}

	/**
	 * 透明度变化
	 */
	public void click1(View view) {
		Animation animation = AnimationUtils.loadAnimation(this,
				R.anim.alpha_anim);
		iv.startAnimation(animation);
	}

	/**
	 * 缩放
	 */
	public void click2(View view) {
		Animation animation = AnimationUtils.loadAnimation(this,
				R.anim.scale_anim);
		iv.startAnimation(animation);
	}

	/**
	 * 旋转
	 */
	public void click3(View view) {
		Animation animation = AnimationUtils.loadAnimation(this,
				R.anim.rotate_anim);
		iv.startAnimation(animation);
	}

	/**
	 * 平移
	 */
	public void click4(View view) {
		Animation animation = AnimationUtils.loadAnimation(this,
				R.anim.translate_anim);
		iv.startAnimation(animation);
	}

	/**
	 * 组合动画
	 */
	public void click5(View view) {
		Animation animation = AnimationUtils.loadAnimation(this,
				R.anim.set_anim);
		iv.startAnimation(animation);
	}
}





  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值