android动画编
16lz
2021-01-23
四月份来了,我也要加紧学习了,下面的动画类型
看看实现的代码package com.smart;import android.app.Activity;import android.os.Bundle;import android.view.View;import android.view.animation.Animation;import android.view.animation.AnimationUtils;import android.view.animation.TranslateAnimation;import android.widget.AdapterView;import android.widget.ArrayAdapter;import android.widget.Spinner;public class Main extends Activity implements AdapterView.OnItemSelectedListener{private static final String[] INTERPOLATORS={"加快", "减速", "加快/减速", "预料","过冲", "预计/过冲", "弹跳" };//类型 @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main); Spinner s=(Spinner)findViewById(R.id.spinner); ArrayAdapter<String> adapter=new ArrayAdapter<String>(this,android.R.layout.simple_spinner_item,INTERPOLATORS); adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item); s.setAdapter(adapter);//得到控件 s.setOnItemSelectedListener(this); } @Overridepublic void onItemSelected(AdapterView<?> parent, View v, int position,long id) {final View target=(View)findViewById(R.id.target);final View targetParent=(View)target.getParent();//得到动画Animation animation= new TranslateAnimation(0.0f, targetParent.getWidth()- target.getWidth()- targetParent.getPaddingLeft()- targetParent.getPaddingRight(), 0.0f, 0.0f);animation.setDuration(1000);animation.setStartOffset(300);animation.setRepeatMode(Animation.RESTART);animation.setRepeatCount(Animation.INFINITE);//选择动来类型switch (position) {case 0:animation.setInterpolator(AnimationUtils.loadInterpolator(this, android.R.anim.accelerate_interpolator));break;case 1:animation.setInterpolator(AnimationUtils.loadInterpolator(this, android.R.anim.decelerate_interpolator));break;case 2:animation.setInterpolator(AnimationUtils.loadInterpolator(this, android.R.anim.accelerate_decelerate_interpolator));break;case 3:animation.setInterpolator(AnimationUtils.loadInterpolator(this, android.R.anim.anticipate_interpolator));break;case 4:animation.setInterpolator(AnimationUtils.loadInterpolator(this, android.R.anim.overshoot_interpolator));break;case 5:animation.setInterpolator(AnimationUtils.loadInterpolator(this, android.R.anim.anticipate_overshoot_interpolator));break;case 6:animation.setInterpolator(AnimationUtils.loadInterpolator(this, android.R.anim.bounce_interpolator));break;}target.startAnimation(animation);}@Overridepublic void onNothingSelected(AdapterView<?> arg0) {}}XML代码<?xml version="1.0" encoding="utf-8"?><LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:orientation="vertical" android:padding="10dip" android:layout_width="fill_parent" android:layout_height="wrap_content" android:clipToPadding="false" ><TextView android:id="@+id/target" android:layout_width="wrap_content" android:layout_height="wrap_content" android:textSize="16sp" android:text="朋友,看看我,跑得多快!" /> <TextView android:layout_width="fill_parent" android:layout_height="wrap_content" android:textSize="15dip" android:layout_marginBottom="5dip" android:text="请选择动画类型" /> <Spinner android:id="@+id/spinner" android:layout_width="fill_parent" android:layout_height="wrap_content" /></LinearLayout>
更多相关文章
- Android 自定义Gif动画
- Android Design: 九种常见Activity及代码解析之"Login Activity"
- [CSDN]Android应用程序进程启动过程的源代码分析
- Android 9.0 开关机动画流程分析
- Android开源项目源代码分享
- 如何用代码区分android TV和手机? 适配Android TV ?