<span style="font-size:32px;color:#ff0000;"><strong>Drawable制作补间动画效果</strong></span>
<span style="color:#ff0000;"><strong><span style="font-size:32px;"><span style="font-family: monospace; white-space: pre; background-color: rgb(240, 240, 240);"></span></span></strong></span><pre name="code" class="java"><span style="font-size:32px;">1获得Animation对象 <span style="font-family: monospace; white-space: pre; background-color: rgb(240, 240, 240);"></span></span><pre name="code" class="java"><span style="font-size:32px;">Animation <strong style="font-family: Arial, Helvetica, sans-serif;"></strong></span><pre name="code" class="java" style="display: inline !important;">anim=AnimationUtils.loadAnimation(this,R.anim.tween);
<strong style="font-family: Arial, Helvetica, sans-serif;"></strong><pre name="code" class="java" style="display: inline !important;"><span style="font-size:32px;"><span style="font-family: monospace; white-space: pre; background-color: rgb(240, 240, 240);"></span></span><pre name="code" class="java"><span style="font-size:32px;">2保留变换之后的状态!!! anim.setFillAfter(true);</span>
<span style="font-size:24px;"></span><pre name="code" class="java"><span style="font-size: 24px;">tween.xml</span>
<?xml version="1.0" encoding="utf-8"?> <set xmlns:android="http://schemas.android.com/apk/res/android" android:interpolator="@android:anim/decelerate_interpolator"> <!-- android:interpolator匀加速 匀减速 匀速 --> <!-- android:fillAfter="true"保留结束的状态 --> <!-- 旋转和缩放需要基点 android:pivotX="50%" android:pivotY="50%" --> <alpha android:fromAlpha="1" android:toAlpha="0.6" android:fillAfter="true" android:duration="2000"/> <rotate android:fromDegrees="0" android:toDegrees="1800" android:fillAfter="true" android:pivotX="50%" android:pivotY="50%" android:duration="2000"/> </set>
<span style="font-size:24px;color:#ff0000;"><strong>在主.java中</strong></span>
<span style="font-size:24px;color:#ff0000;"><strong> </strong></span>
<span style="font-size:24px;"><strong></strong></span><pre name="code" class="java">package com.example.drawable_tween; import android.os.Bundle; import android.app.Activity; import android.view.Menu; import android.view.View; import android.view.animation.Animation; import android.view.animation.AnimationUtils; import android.widget.Button; import android.widget.ImageView; /** * 补间动画 Animation * @author LiTing * */ public class MainActivity extends Activity { //Animation对象 Animation anim; ImageView image; Button btn; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.view); image=(ImageView) findViewById(R.id.image); btn= (Button) findViewById(R.id.button1); //获得Animation对象 anim=AnimationUtils.loadAnimation(this,R.anim.tween); //保留变换之后的状态!!! anim.setFillAfter(true); } public void myclick(View v) { image.startAnimation(anim); } }
<span style="font-size:24px;"><strong> </strong></span>
<span style="font-size:24px;"><strong> </strong></span>
<span style="font-size:24px;color:#ff0000;"><strong> </strong></span>