六狼论坛

 找回密码
 立即注册

QQ登录

只需一步,快速开始

新浪微博账号登陆

只需一步,快速开始

搜索
查看: 61|回复: 0

TextView中各种Interpolator的使用

[复制链接]

升级  35.2%

212

主题

212

主题

212

主题

进士

Rank: 4

积分
676
 楼主| 发表于 2013-1-15 02:20:52 | 显示全部楼层 |阅读模式
package net.blogjava.mobile.interpolators;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 implementsAdapterView.OnItemSelectedListener {private static final String[] INTERPOLATORS = { "Accelerate", "Decelerate","Accelerate/Decelerate", "Anticipate", "Overshoot","Anticipate/Overshoot", "Bounce" };@Overridepublic 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);}public void onItemSelected(AdapterView parent, View v, int position, long id) {final View target = 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);}public void onNothingSelected(AdapterView parent) {}}
您需要登录后才可以回帖 登录 | 立即注册 新浪微博账号登陆

本版积分规则

快速回复 返回顶部 返回列表