现在的位置: 首页 > 综合 > 正文

Android—Tween动画

2013年07月13日 ⁄ 综合 ⁄ 共 3234字 ⁄ 字号 评论关闭

新建一个工程,在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

抱歉!评论已关闭.