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 implements
AdapterView.OnItemSelectedListener {
private static final String[] INTERPOLATORS = { "Accelerate", "Decelerate",
"Accelerate/Decelerate", "Anticipate", "Overshoot",
"Anticipate/Overshoot", "Bounce" };
@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);
}
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) {
}
}
分享到:
相关推荐
CheckableTextView Checkable TextView [KOTLIN]:high_voltage:用Kotlin编写的简单灵活的Checked TextView或Checkable TextView:high_voltage:新增功能CheckableTextView Checkable TextView [KOTLIN]:high_voltage:...
12.3.1 在Android应用中使用 OpenGL ES 454 12.3.2 绘制平面上的多边形 457 12.3.3 旋转 463 12.4 绘制3D图形 465 12.4.1 构建3D图形 465 12.4.2 应用纹理贴图 469 12.5 本章小结 475 第13章 ...
12.3.1 在Android应用中使用 OpenGL ES 454 12.3.2 绘制平面上的多边形 457 12.3.3 旋转 463 12.4 绘制3D图形 465 12.4.1 构建3D图形 465 12.4.2 应用纹理贴图 469 12.5 本章小结 475 第13章 Android的网络应用 476 ...
12.3.1 在Android应用中使用 OpenGL ES 454 12.3.2 绘制平面上的多边形 457 12.3.3 旋转 463 12.4 绘制3D图形 465 12.4.1 构建3D图形 465 12.4.2 应用纹理贴图 469 12.5 本章小结 475 第13章 Android的网络应用 476 ...
2.3、基本界面组件:TextView、EditText; Button、ImageButton; 9Patch; RadioButton、CheckBox; ToggleButton;AnalogClock、DigitalClock; ImageView; 2.4、高级界面组件:AutoCompleteTextView; Spinner; ...
2.3、基本界面组件:TextView、EditText; Button、ImageButton; 9Patch; RadioButton、CheckBox; ToggleButton;AnalogClock、DigitalClock; ImageView; 2.4、高级界面组件:AutoCompleteTextView; Spinner; ...
mText = (TextView) findViewById(R.id.textView1); mImageView01 = (ImageView) findViewById(R.id.m1); mButton = (Button) findViewById(R.id.button1); randon(); mImageView01....
在API Demo的View->Animation下可以找到四个Animation的Demo,第一个3D Translate比较复杂,最后再讲,先讲第2个Interpolator。该Activity对应的是view包内的Animation3.java,和layout的animation_3.xml。 界面的...
本篇难度较大,慎入 也许可以先去看总结在来一起分析 从我们写的开始进入: fun click(view: View) { val textView = findViewById(R... animator.interpolator = LinearInterpolator() animator.start() } 首先第
4.5.2 Interpolator 136 4.5.3 AnimationSet 137 4.5.4 自定义动画 138 4.6 Resource介绍 143 4.6.1 资源类型 143 4.6.2 使用资源 144 4.6.3 资源适配 146 4.7 俄罗斯方块实例 147 4.7.1 方块的数据结构 147 4.7.2 ...
1.概述对所有基础控件(包括,嵌套滑动例如RecyclerView、NestedScrollView,普通的TextView、ListView、ScrollerView、LinearLayout等)提供下拉刷新、上拉加载的支持,处理了横向滑动冲突(例如:顶部banner的情况) ...