Android---Tween动画示例(XML定义的动画)
1、在res/anim目录下新建XML文件:tween_anim.xml
[html]
<?xml version="1.0" encoding="utf-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android">
<alpha
android:fromAlpha="0.2"
android:toAlpha="1.0"
android:duration="3000"
android:repeatMode="reverse"
android:repeatCount="10" />
<scale
android:fromXScale="0.2"
android:toXScale="1.0"
android:fromYScale="0.2"
android:toYScale="1.0"
android:pivotX="50%"
android:pivotY="50%"
android:duration="3000"
android:repeatMode="reverse"
android:repeatCount="10" />
<translate
android:fromXDelta="50"
android:toXDelta="100"
android:fromYDelta="50"
android:toYDelta="100"
android:duration="3000"
android:repeatMode="restart"
android:repeatCount="10" />
<rotate
android:fromDegrees="0"
android:toDegrees="360"
android:duration="3000"
android:repeatMode="restart"
android:repeatCount="10" />
</set>
<?xml version="1.0" encoding="utf-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android">
<alpha
android:fromAlpha="0.2"
android:toAlpha="1.0"
android:duration="3000"
android:repeatMode="reverse"
android:repeatCount="10" />
<scale
android:fromXScale="0.2"
android:toXScale="1.0"
android:fromYScale="0.2"
android:toYScale="1.0"
android:pivotX="50%"
android:pivotY="50%"
android:duration="3000"
android:repeatMode="reverse"
android:repeatCount="10" />
<translate
android:fromXDelta="50"
android:toXDelta="100"
android:fromYDelta="50"
android:toYDelta="100"
android:duration="3000"
android:repeatMode="restart"
android:repeatCount="10" />
<rotate
android:fromDegrees="0"
android:toDegrees="360"
android:duration="3000"
android:repeatMode="restart"
android:repeatCount="10" />
</set>
2、在res/layout目录下新建XML文件:tween_anim_layout.xml
[html]
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent">
<ImageView
android:id="@+id/imgTween"
android:src="@drawable/c01"
android:layout_height="wrap_content"
android:layout_width="wrap_content"
android:layout_weight="1.0" />
<Button
android:id="@+id/btnControl"
android:text="开始"
android:layout_width="match_parent"
android:layout_height="wrap_content" />
</LinearLayout>
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent">
<ImageView
android:id="@+id/imgTween"
android:src="@drawable/c01"
android:layout_height="wrap_content"
android:layout_width="wrap_content"
android:layout_weight="1.0" />
<Button
android:id="@+id/btnControl"
android:text="开始"
android:layout_width="match_parent"
android:layout_height="wrap_content" />
</LinearLayout>
3、Activity里面添加代码:
[java]
package com.bison;
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 TweenAnimationDemo extends Activity {
// 声明一个开始停止的标识符
private boolean flags = true;
private ImageView imgTween;
private Button btnCtrl;
/** 初始化 */
public void init() {
imgTween = (ImageView) findViewById(R.id.imgTween);
//
补充:移动开发 , Android ,