animation_3.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="match_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="26sp"
android:text="@string/animation_3_text"/> <TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="20dip"
android:layout_marginBottom="5dip"
android:text="@string/animation_2_instructions" /> <Spinner
android:id="@+id/spinner"
android:layout_width="match_parent"
android:layout_height="wrap_content" /> </LinearLayout>

Animation3.java:

 package com.example.android.apis.view;

 import com.example.android.apis.R;

 import android.app.Activity;
import android.os.Bundle;
import android.view.View;
import android.view.animation.AnimationUtils;
import android.view.animation.Animation;
import android.view.animation.TranslateAnimation;
import android.widget.AdapterView;
import android.widget.ArrayAdapter;
import android.widget.Spinner; public class Animation3 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.animation_3); 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 a = new TranslateAnimation(0.0f,
targetParent.getWidth() - target.getWidth() - targetParent.getPaddingLeft() -
targetParent.getPaddingRight(), 0.0f, 0.0f);
a.setDuration(1000);
a.setStartOffset(300);
a.setRepeatMode(Animation.RESTART);
a.setRepeatCount(Animation.INFINITE); switch (position) {
case 0:
a.setInterpolator(AnimationUtils.loadInterpolator(this,
android.R.anim.accelerate_interpolator));
break;
case 1:
a.setInterpolator(AnimationUtils.loadInterpolator(this,
android.R.anim.decelerate_interpolator));
break;
case 2:
a.setInterpolator(AnimationUtils.loadInterpolator(this,
android.R.anim.accelerate_decelerate_interpolator));
break;
case 3:
a.setInterpolator(AnimationUtils.loadInterpolator(this,
android.R.anim.anticipate_interpolator));
break;
case 4:
a.setInterpolator(AnimationUtils.loadInterpolator(this,
android.R.anim.overshoot_interpolator));
break;
case 5:
a.setInterpolator(AnimationUtils.loadInterpolator(this,
android.R.anim.anticipate_overshoot_interpolator));
break;
case 6:
a.setInterpolator(AnimationUtils.loadInterpolator(this,
android.R.anim.bounce_interpolator));
break;
} target.startAnimation(a);
} public void onNothingSelected(AdapterView<?> parent) {
}
}

效果如下,文字会根据不同的效果执行动画显示效果:

android中的简单animation(三)accelerate(加速),decelerate(减速),anticipate,overshoot,bounce的更多相关文章

  1. android中的简单animation(四)3D transition

    animation_main_screen.xml: <?xml version="1.0" encoding="utf-8"?> <Fram ...

  2. android中的简单animation(二)push up,push left,cross fade,hyperspace

    animation_2.xml: <?xml version="1.0" encoding="utf-8"?> <LinearLayout x ...

  3. android中的简单animation(一)shake

    1.shake animation_1.xml: <?xml version="1.0" encoding="utf-8"?> <Linear ...

  4. android中解析文件的三种方式

    android中解析文件的三种方式     好久没有动手写点东西了,最近在研究android的相关技术,现在就android中解析文件的三种方式做以下总结.其主要有:SAX(Simple API fo ...

  5. MVP架构在xamarin android中的简单使用

    好几个月没写文章了,使用xamarin android也快接近两年,还有一个月职业生涯就到两个年了,从刚出来啥也不会了,到现在回头看这个项目,真jb操蛋(真辛苦了实施的人了,无数次吐槽怎么这么丑),怪 ...

  6. Gradle在Android中的简单使用

    Gradle在Android中简单的使用 还望支持个人博客站:http://www.enjoytoday.cn Android Studio 使用gradle进行工程构建,为了更好的了解整个andro ...

  7. URL转Drawable之 Android中获取网络图片的三种方法

    转载自: http://doinone.iteye.com/blog/1074283 Android中获取网络图片是一件耗时的操作,如果直接获取有可能会出现应用程序无响应(ANR:Applicatio ...

  8. Android中xml设置Animation动画效果详解

    在 Android 中, Animation 动画效果的实现可以通过两种方式进行实现,一种是 tweened animation 渐变动画,另一种是 frame by frame animation ...

  9. android中实现简单的聊天功能

    这个例子只是简单的实现了单机版的聊天功能,自己跟自己聊,啦啦~~ 主要还是展示RecyclerView控件的使用吧~ 参考我之前写的文章: android中RecyclerView控件的使用 andr ...

随机推荐

  1. UIScrollView的API

    @property(nonatomic, weak) id<UIScrollViewDelegate> delegate; 滚动视图对象的委托. @property(nonatomic) ...

  2. color转成image对象

    .h //颜色转换成图片 + (UIImage *)imageFromColor:(UIColor *)color; .m //颜色转换成图片 + (UIImage *)imageFromColor: ...

  3. 数据包报文格式(IP包、TCP报头、UDP报头)

    转自: https://blog.51cto.com/lyhbwwk/2162568 一.IP包格式 IP数据包是一种可变长分组,它由首部和数据负载两部分组成.首部长度一般为20-60字节(Byte) ...

  4. 2.2 logistic回归

    logistic回归,是一个学习算法,用在监督学习问题中, 输出标签y是0或者1的时候,这是一个二元分类问题, 给定一个输入x,一张图,你希望识别出这是不是猫图, 需要一个算法,可以给出一个预测值,我 ...

  5. leetcode刷题-- 5. 动态规划

    动态规划思路 参考 状态转移方程: 明确「状态」-> 定义dp数组/函数的含义 -> 明确「选择」-> 明确 base case 试题 53最大子序和 题目描述 53 给定一个整数数 ...

  6. 夯实Java基础(二十四)——Java8新特征之Optional类

    1.概述 对于Java程序员来说,到目前为止出现次数最多的应该是NullpointException,它是导致Java应用程序失败的最常见原因.之前处理空指针我们必须先通过条件先去判断,然后再确认是否 ...

  7. while语句及批量创建用户!

    1.while 循环语句的作用:重复测试某个条件,只要条件成立则反复执行2.while 语句结构while 条件测试操作do命令序列done ============================= ...

  8. luogu P4014 分配问题

    简单的费用流问题,每个人对每个任务连边,每个任务对汇点连,源点对每个人连,最大费用取反即可 #include<bits/stdc++.h> using namespace std; #de ...

  9. linux查漏补缺-linux命令行安装mysql

    apt安装 sudo apt-get update sudo apt-get install mysql-server root@192:/sys/fs/cgroup# apt-get install ...

  10. MySQL定时任务event,储存过程(定时删除指定时间前90天指定表的数据)

    MySQL定时任务event,储存过程(定时删除指定时间前90天指定表的数据) 分类: MySql5.x2014-06-23 15:16 1266人阅读 评论(0) 收藏 举报 mysql数据库 &l ...