首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 移动开发 > Android >

Android Animation->TweemAnimation使用

2012-07-22 
Android Animation---TweemAnimation运用------------------------------------旋转反转//reverse rotate

Android Animation--->TweemAnimation运用

-------------------------

-----------旋转+反转

//reverse +rotate
<?xml version="1.0" encoding="UTF-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android"
    android:shareInterpolator="false" >

    <rotate
        android:repeatCount="10"
        android:repeatMode="reverse"
        android:duration="8000"
        android:fromDegrees="0"
        android:pivotX="50%"
        android:pivotY="50%"
        android:toDegrees="360" >
    </rotate>

</set>

-------------颜色亮到透明 反复
<?xml version="1.0" encoding="UTF-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android"
    android:shareInterpolator="false" >

    <alpha
        android:duration="3000"
        android:fromAlpha="0.2"
        android:repeatCount="10"
        android:repeatMode="reverse"
        android:toAlpha="1.0" />

</set>

--------------------------------.java

package gongzibai.co.cc;

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

public class Animation1Activity extends
  Activity {
 /** Called when the activity is first created. */
 @Override
 public void onCreate(
   Bundle savedInstanceState) {
  super.onCreate(savedInstanceState);
  setContentView(R.layout.main);
  final ImageView mImageView = (ImageView) findViewById(R.id.imageView1);
  mImageView
    .setImageResource(R.drawable.icon);

  findViewById(R.id.button15)
    .setOnClickListener(
      new OnClickListener() {

       @Override
       public void onClick(
         View v) {
        // TODO Auto-generated method stub
        final Animation animation2 = AnimationUtils
          .loadAnimation(
            Animation1Activity.this,
            R.anim.setanimation1);

//mimageview add animation 

        mImageView
          .startAnimation(animation2);

       }
      });
  findViewById(R.id.button2)
    .setOnClickListener(
      new OnClickListener() {

       @Override
       public void onClick(
         View v) {
        // TODO Auto-generated method stub

        final Animation animation1 = AnimationUtils
          .loadAnimation(
            Animation1Activity.this,
            R.anim.setanimation);
        mImageView
          .startAnimation(animation1);

       }
      });

  findViewById(R.id.button3)
    .setOnClickListener(
      new OnClickListener() {

       @Override
       public void onClick(
         View v) {
        // TODO Auto-generated method stub

        final Animation animation2 = AnimationUtils
          .loadAnimation(
            Animation1Activity.this,
            R.anim.setanimation2);
        mImageView
          .startAnimation(animation2);

       }
      });

  findViewById(R.id.button4)
    .setOnClickListener(
      new OnClickListener() {

       @Override
       public void onClick(
         View v) {
        new AnimationUtils();
        // TODO Auto-generated method stub
        final Animation animation3 = AnimationUtils
          .loadAnimation(
            Animation1Activity.this,
            R.anim.alpha_animation);
        mImageView
          .startAnimation(animation3);

       }
      });
 }
}

-----------------------

-----


--------------FRAMEANIMATION自动运行

// auto run--->hasfocus--->onwindowfocusChanged...
@Override
 public void onWindowFocusChanged(
   boolean hasFocus) {
  // TODO Auto-generated method stub
  if (hasFocus) {
   fireanimation.start();

  } else {
   fireanimation.stop();
  }
  super.onWindowFocusChanged(hasFocus);
 }
------------
-------------.java
mImageView
    .setBackgroundResource

(R.anim.fireanim);
  
  fireanimation = (AnimationDrawable) mImageView
    .getBackground();
---------<?xml version="1.0" encoding="UTF-8"?>

// add <animation-list>  </animation-list>

//add <item>
<animation-list

xmlns:android="http://schemas.android.com/apk/res/android"
    android:oneshot="true" >

    <item
        android:drawable="@drawable/fire01"
        android:duration="100"/>

    <item
        android:drawable="@drawable/fire02"
        android:duration="600"/>
</animation-list>

 

 -----------XML里的IMAGEVIEW不能加载图片,否则,FRAMEANIMATION无效果...

热点排行