Android---Tween动画

新建一个工程,在res文件夹下新建anim文件夹,在anin文件夹下新建以下xml文件

 

 

alpha.xml:透明度

rotate.xml:旋转

scale.xml:比例

translate.xml:平衡

translate.xml(这个xml综合上面4种效果)

 

alpha.xml代码如下:

 

<set xmlns:android="http://schemas.android.com/apk/res/android"
    android:shareInterpolator="false" >

    <alpha

        //设置效果时间
        android:duration="5000"

        //设置透明度,透明度范围为0到1.0,0为完全透明,1.0为不透明
        android:fromAlpha="1.0"
        android:toAlpha="0" />

</set>


 

 

 

rotate.xml代码如下 :

 

<set xmlns:android="http://schemas.android.com/apk/res/android"
    android:shareInterpolator="false" >

    <rotate
        android:duration="5000"

        //从0度旋转到180度
        android:fromDegrees="0"

        android:toDegress="180"

        //50%表示旋转中心点为图片中心
        android:pivotX="50%"
        android:pivotY="50%"
         />

</set>


 

scale.xml代码如下 :

 

<set xmlns:android="http://schemas.android.com/apk/res/android"
    android:shareInterpolator="false" >

    <scale
        android:duration="5000"

        //开始状态,1.0表示无伸缩
        android:fromXScale="1.0"
        android:fromYScale="1.0"
        android:pivotX="50%"
        android:pivotY="50%"

        //伸缩比例,根据上面的1.0,这里是放大5倍的意思
        android:toXScale="5.0"
        android:toYScale="5.0" />

</set>


 

 

translate.xml代码如下:

 

<set xmlns:android="http://schemas.android.com/apk/res/android"
    android:shareInterpolator="false" >

    <translate
        android:duration="5000"

        //未平移时的坐标位置
        android:fromXDelta="1.0"
        android:fromYDelta="1.0"

       //平移后的坐标位置
        android:toXDelta="100.0"
        android:toYDelta="100.0" />

</set>


 

 

tween.xml代码如下:

 

<set xmlns:android="http://schemas.android.com/apk/res/android"
    android:shareInterpolator="false" >

    <alpha
        android:duration="5000"
        android:fromAlpha="1.0"
        android:toAlpha="0" />

    <rotate
        android:duration="5000"
        android:fromDegrees="0"
        android:pivotX="50%"
        android:pivotY="50%"
        android:toDegrees="180"
        android:toYScale="0.0" />

    <scale
        android:duration="5000"
        android:fromXScale="1.0"
        android:fromYScale="1.0"
        android:pivotX="50%"
        android:pivotY="50%"
        android:toXScale="5.0"
        android:toYScale="5.0" />

    <translate
        android:duration="5000"
        android:fromXDelta="1.0"
        android:fromYDelta="1.0"
        android:toXDelta="100.0"
        android:toYDelta="100.0" />

</set>


 

 

main.xml代码如下 :

 

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical"
    android:gravity="center" >

    <ImageView
        android:id="@+id/imageView1"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:src="@drawable/ic_launcher" 
        />

</LinearLayout>


 

 

 

activity代码如下:

 

package com.mrzhu.mytween;

import android.app.Activity;
import android.os.Bundle;
import android.view.animation.Animation;
import android.view.animation.AnimationUtils;
import android.widget.ImageView;

public class MytweenActivity extends Activity {

//声明一个ImageView和Animation

 private ImageView  imagetext;
 private Animation animation;


 
 @Override
 public void onCreate(Bundle savedInstanceState) {
  super.onCreate(savedInstanceState);
  setContentView(R.layout.main);

//将要实现的效果通过id绑定到animaiton上

  // Animation animation = AnimationUtils.loadAnimation(this, R.anim.alpha);
  //Animation animation = AnimationUtils.loadAnimation(this, R.anim.scale);
  //Animation animation = AnimationUtils.loadAnimation(this, R.anim.rotate);
  //Animation animation = AnimationUtils.loadAnimation(this, R.anim.translate);
  animation = AnimationUtils.loadAnimation(this, R.anim.tween);

//取得ImageView控件
  imagetext = (ImageView)findViewById(R.id.imageView1);

//开始动画
  imagetext.startAnimation(animation);
 }
}


 

 

资源下载:http://download.csdn.net/detail/zlqqhs/4681710

评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值