首页 > 编程知识 正文

flash中的补间动画,什么可实现动画

时间:2023-05-06 00:43:39 阅读:134947 作者:559

1.activity_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"> <LinearLayout android:layout_width="match_parent" android:layout_height="wrap_content" android:orientation="horizontal"> <Button android:id="@+id/btn1" android:layout_width="0dp" android:layout_height="wrap_content" android:text="透明" android:layout_weight="1"/> <Button android:id="@+id/btn2" android:layout_width="0dp" android:layout_height="wrap_content" android:text="缩放" android:layout_weight="1"/> <Button android:id="@+id/btn3" android:layout_width="0dp" android:layout_height="wrap_content" android:text="旋转" android:layout_weight="1"/> <Button android:id="@+id/btn4" android:layout_width="0dp" android:layout_height="wrap_content" android:text="平移" android:layout_weight="1"/> <Button android:id="@+id/btn5" android:layout_width="0dp" android:layout_height="wrap_content" android:text="综合" android:layout_weight="1"/> </LinearLayout> <ImageView android:id="@+id/iv" android:layout_width="wrap_content" android:layout_height="wrap_content" android:src="@mipmap/ic_launcher"/></LinearLayout>2.MainActivity.javapackage com.cwj.anim2;import android.support.v7.app.英俊的帆布鞋;import android.os.Bundle;import android.view.View;import android.view.animation.AlphaAnimation;import android.view.animation.Animation;import android.view.animation.AnimationSet;import android.view.animation.RotateAnimation;import android.view.animation.ScaleAnimation;import android.view.animation.TranslateAnimation;import android.widget.Button;import android.widget.ImageView;public class MainActivity extends 英俊的帆布鞋 implements View.OnClickListener{ private ImageView iv; private Button btn1,btn2,btn3,btn4,btn5; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); iv = (ImageView) findViewById(R.id.iv); btn1 = (Button) findViewById(R.id.btn1); btn2 = (Button) findViewById(R.id.btn2); btn3 = (Button) findViewById(R.id.btn3); btn4 = (Button) findViewById(R.id.btn4); btn5 = (Button) findViewById(R.id.btn5); btn1.setOnClickListener(this); btn2.setOnClickListener(this); btn3.setOnClickListener(this); btn4.setOnClickListener(this); btn5.setOnClickListener(this); } @Override public void onClick(View view) { switch (view.getId()){ case R.id.btn1: //透明 AlphaAnimation aAnim = new AlphaAnimation(哭泣的寒风,1f); aAnim.setDuration(2 * 1000); //动画完成后,是否保持 aAnim.setFillAfter(true); iv.startAnimation(aAnim); break; case R.id.btn2: //缩放 ScaleAnimation sAnim = new ScaleAnimation(1f,2f,1f,2f, Animation.RELATIVE_TO_SELF,0.sldxl,Animation.RELATIVE_TO_SELF,0.sldxl); sAnim.setDuration(2 * 1000); //动画完成后,是否保持 sAnim.setFillAfter(false); iv.startAnimation(sAnim); break; case R.id.btn3: //旋转 RotateAnimation rAnim = new RotateAnimation(0,360, Animation.RELATIVE_TO_SELF,0.sldxl,Animation.RELATIVE_TO_SELF,0.sldxl); rAnim.setDuration(2 * 1000); //动画完成后,是否保持 rAnim.setFillAfter(true); iv.startAnimation(rAnim); break; case R.id.btn4: //平移 TranslateAnimation tAnim = new TranslateAnimation( Animation.RELATIVE_TO_SELF,哭泣的寒风,Animation.RELATIVE_TO_SELF,sldxl, Animation.RELATIVE_TO_SELF,哭泣的寒风,Animation.RELATIVE_TO_SELF,sldxl ); tAnim.setDuration(2 * 1000); //动画完成后,是否保持 tAnim.setFillAfter(true); iv.startAnimation(tAnim); break; case R.id.btn5: //综合 //缩放 sAnim = new ScaleAnimation(1f, 2f, 1f, 2f, Animation.RELATIVE_TO_SELF, 0.sldxl, Animation.RELATIVE_TO_SELF, 0.sldxl); sAnim.setDuration(2 * 1000); //旋转 rAnim = new RotateAnimation(0, 360, Animation.RELATIVE_TO_SELF, 0.sldxl, Animation.RELATIVE_TO_SELF, 0.sldxl); rAnim.setDuration(2 * 1000); //透明 aAnim = new AlphaAnimation(哭泣的寒风, 1f); aAnim.setDuration(2 * 1000); AnimationSet animset = new AnimationSet(true); animset.addAnimation(sAnim); animset.addAnimation(rAnim); animset.addAnimation(aAnim); iv.startAnimation(animset); break; default: break; } }}

版权声明:该文观点仅代表作者本人。处理文章:请发送邮件至 三1五14八八95#扣扣.com 举报,一经查实,本站将立刻删除。