android中的简单animation(三)accelerate(加速),decelerate(减速),anticipate,overshoot,bounce
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的更多相关文章
- android中的简单animation(四)3D transition
animation_main_screen.xml: <?xml version="1.0" encoding="utf-8"?> <Fram ...
- android中的简单animation(二)push up,push left,cross fade,hyperspace
animation_2.xml: <?xml version="1.0" encoding="utf-8"?> <LinearLayout x ...
- android中的简单animation(一)shake
1.shake animation_1.xml: <?xml version="1.0" encoding="utf-8"?> <Linear ...
- android中解析文件的三种方式
android中解析文件的三种方式 好久没有动手写点东西了,最近在研究android的相关技术,现在就android中解析文件的三种方式做以下总结.其主要有:SAX(Simple API fo ...
- MVP架构在xamarin android中的简单使用
好几个月没写文章了,使用xamarin android也快接近两年,还有一个月职业生涯就到两个年了,从刚出来啥也不会了,到现在回头看这个项目,真jb操蛋(真辛苦了实施的人了,无数次吐槽怎么这么丑),怪 ...
- Gradle在Android中的简单使用
Gradle在Android中简单的使用 还望支持个人博客站:http://www.enjoytoday.cn Android Studio 使用gradle进行工程构建,为了更好的了解整个andro ...
- URL转Drawable之 Android中获取网络图片的三种方法
转载自: http://doinone.iteye.com/blog/1074283 Android中获取网络图片是一件耗时的操作,如果直接获取有可能会出现应用程序无响应(ANR:Applicatio ...
- Android中xml设置Animation动画效果详解
在 Android 中, Animation 动画效果的实现可以通过两种方式进行实现,一种是 tweened animation 渐变动画,另一种是 frame by frame animation ...
- android中实现简单的聊天功能
这个例子只是简单的实现了单机版的聊天功能,自己跟自己聊,啦啦~~ 主要还是展示RecyclerView控件的使用吧~ 参考我之前写的文章: android中RecyclerView控件的使用 andr ...
随机推荐
- 操作系统OS,Python - 有了GIL为什么还要threading.Lock()?
参考: https://stackoverflow.com/questions/49859287/what-is-the-need-of-threading-lock-when-cpython-has ...
- Hibernate笔记一
背景 jdbc的优缺点 A:直接操作底层,提供了简单,便捷的访问数据库方法,跨平台比较强,灵活,可以写很多赋值的SQL语句:是最底层的数据库操作,所以效率比较高,Sql语句可以自己选择写,采用效率最高 ...
- springdata框架
SpringData jpa: JPA(Java Persistence API)是当年的 Sun 官方提出的 Java 持久化规范. Spring Data JPA 是 Spring 基 ...
- Linux (Ubuntu) 服务器安装MySQL,设置不限ip,root远程密码访问
1.注释bind-address = 127.0.0.1 sudo vim /etc/mysql/mysql.conf.d/mysqld.cnf 将bind-address = 127.0.0.1 ...
- js给元素添加样式[addClass][hasClass]
function addClass(el, className) { if (hasClass(el, className)) { return } let newClass = el.classNa ...
- Codeforces 1304D. Shortest and Longest LIS
根据题目,我们可以找最短的LIS和最长的LIS,找最短LIS时,可以将每一个increase序列分成一组,从左到右将最大的还未选择的数字填写进去,不同组之间一定不会存在s[i]<s[j]的情况, ...
- unity优化-CPU(网上整理)
CPU方面性能考虑:引擎和代码渲染模块.动画模块.物理模块.ui模块.粒子模块.加载模块.GC模块最重要的是渲染模块.UI模块和加载模块1.渲染模块主要是:场景.物体和特效的渲染a.降低Draw ca ...
- SpringTest
Spring Test 1.对junit的一个扩展 必须先导入junit jar包 2.简化获取bean的步骤 它的底层也是IOC容器 3.IOC的全部 junit的全部 junit的版本必须是 ...
- 为安卓手机刷上手机kali系统Nethunter
kali Nethunter是一个装在手机上的kali,集成了kali的工具包,hid,无线攻击等等. 本文主要叙述如何安装此系统并正确的配置.不让你走弯路. 首先我们拒绝傻瓜安装软件 kali ne ...
- day14-Python运维开发基础(内置函数、pickle序列化模块、math数学模块)
1. 内置函数 # ### 内置函数 # abs 绝对值函数 res = abs(-10) print(res) # round 四舍五入 (n.5 n为偶数则舍去 n.5 n为奇数,则进一!) 奇进 ...