Android控件Tween动画(补间动画)实现方法示例
作者:迟做总比不做强 发布时间:2021-12-31 17:46:39
标签:Android,Tween动画,补间动画
本文实例讲述了Android控件Tween动画(补间动画)实现方法。分享给大家供大家参考,具体如下:
Android动画中的Tween动画:是把控件对象不断的进行图像变化来产生旋转、平移、放缩和渐变等动画效果。
/**
* 控件Tween动画
*
* @description:
* @author ldm
* @date 2016-6-22 下午5:26:24
*/
public class TweenActivity extends Activity {
private SeekBar seekBarX;// 拖动条控件
private SeekBar seekBarY;
private SeekBar scaleSeekBarX;
private SeekBar scaleSeekBarY;
private SeekBar rotationSeekBarX;
private SeekBar rotationSeekBarY;
private SeekBar rotationSeekBarZ;
private Button button;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_tween);
initViews();
initEvents();
}
/**
*
* @description:初始化控件
* @author ldm
* @date 2016-6-22 下午5:26:26
*/
private void initViews() {
button = (Button) findViewById(R.id.button);
seekBarX = (SeekBar) findViewById(R.id.translationX);
seekBarX.setMax(400);
seekBarY = (SeekBar) findViewById(R.id.translationY);
seekBarY.setMax(800);
scaleSeekBarX = (SeekBar) findViewById(R.id.scaleX);
scaleSeekBarX.setMax(50);
scaleSeekBarX.setProgress(10);
scaleSeekBarY = (SeekBar) findViewById(R.id.scaleY);
scaleSeekBarY.setMax(50);
scaleSeekBarY.setProgress(10);
rotationSeekBarX = (SeekBar) findViewById(R.id.rotationX);
rotationSeekBarX.setMax(360);
rotationSeekBarY = (SeekBar) findViewById(R.id.rotationY);
rotationSeekBarY.setMax(360);
rotationSeekBarZ = (SeekBar) findViewById(R.id.rotationZ);
rotationSeekBarZ.setMax(360);
}
/**
*
* @description:控件设置监听事件
* @author ldm
* @date 2016-6-22 下午5:26:26
*/
private void initEvents() {
// 按钮X方向平移动画
seekBarX.setOnSeekBarChangeListener(new SeekBar.OnSeekBarChangeListener() {
public void onStopTrackingTouch(SeekBar seekBar) {
}
public void onStartTrackingTouch(SeekBar seekBar) {
}
public void onProgressChanged(SeekBar seekBar, int progress,
boolean fromUser) {
// X方向平移
button.setTranslationX((float) progress);
}
});
// 按钮Y方向平移动画
seekBarY.setOnSeekBarChangeListener(new SeekBar.OnSeekBarChangeListener() {
public void onStopTrackingTouch(SeekBar seekBar) {
}
public void onStartTrackingTouch(SeekBar seekBar) {
}
public void onProgressChanged(SeekBar seekBar, int progress,
boolean fromUser) {
// Y方向平移
button.setTranslationY((float) progress);
}
});
// 按钮X方向缩放动画
scaleSeekBarX
.setOnSeekBarChangeListener(new SeekBar.OnSeekBarChangeListener() {
public void onStopTrackingTouch(SeekBar seekBar) {
}
public void onStartTrackingTouch(SeekBar seekBar) {
}
public void onProgressChanged(SeekBar seekBar,
int progress, boolean fromUser) {
// X方向缩放
button.setScaleX((float) progress / 10f);
}
});
// 按钮Y方向缩放动画
scaleSeekBarY
.setOnSeekBarChangeListener(new SeekBar.OnSeekBarChangeListener() {
public void onStopTrackingTouch(SeekBar seekBar) {
}
public void onStartTrackingTouch(SeekBar seekBar) {
}
public void onProgressChanged(SeekBar seekBar,
int progress, boolean fromUser) {
// Y方向缩放
button.setScaleY((float) progress / 10f);
}
});
// 按钮X方向旋转动画
rotationSeekBarX
.setOnSeekBarChangeListener(new SeekBar.OnSeekBarChangeListener() {
public void onStopTrackingTouch(SeekBar seekBar) {
}
public void onStartTrackingTouch(SeekBar seekBar) {
}
public void onProgressChanged(SeekBar seekBar,
int progress, boolean fromUser) {
// X方向旋转
button.setRotationX((float) progress);
}
});
// 按钮Y方向旋转动画
rotationSeekBarY
.setOnSeekBarChangeListener(new SeekBar.OnSeekBarChangeListener() {
public void onStopTrackingTouch(SeekBar seekBar) {
}
public void onStartTrackingTouch(SeekBar seekBar) {
}
public void onProgressChanged(SeekBar seekBar,
int progress, boolean fromUser) {
// Y方向旋转
button.setRotationY((float) progress);
}
});
// 按钮Z方向旋转动画
rotationSeekBarZ
.setOnSeekBarChangeListener(new SeekBar.OnSeekBarChangeListener() {
public void onStopTrackingTouch(SeekBar seekBar) {
}
public void onStartTrackingTouch(SeekBar seekBar) {
}
public void onProgressChanged(SeekBar seekBar,
int progress, boolean fromUser) {
// 设置旋转
button.setRotation((float) progress);
}
});
}
}
布局文件R.layout.activity_tween
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/container"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:splitMotionEvents="true" >
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="20dip"
android:orientation="horizontal"
android:splitMotionEvents="true" >
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:paddingLeft="5dip"
android:paddingRight="5dip"
android:text="TX"
android:textStyle="bold" />
<SeekBar
android:id="@+id/translationX"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:orientation="horizontal" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:paddingLeft="15dip"
android:paddingRight="5dip"
android:text="TY"
android:textStyle="bold" />
<SeekBar
android:id="@+id/translationY"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:orientation="horizontal" />
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="20dip"
android:orientation="horizontal"
android:splitMotionEvents="true" >
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:paddingLeft="5dip"
android:paddingRight="5dip"
android:text="SX"
android:textStyle="bold" />
<SeekBar
android:id="@+id/scaleX"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:orientation="horizontal" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:paddingLeft="15dip"
android:paddingRight="5dip"
android:text="SY"
android:textStyle="bold" />
<SeekBar
android:id="@+id/scaleY"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:orientation="horizontal" />
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="20dip"
android:orientation="horizontal"
android:splitMotionEvents="true" >
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:paddingLeft="5dip"
android:paddingRight="5dip"
android:text="X"
android:textStyle="bold" />
<SeekBar
android:id="@+id/rotationX"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:orientation="horizontal" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:paddingLeft="15dip"
android:paddingRight="5dip"
android:text="Y"
android:textStyle="bold" />
<SeekBar
android:id="@+id/rotationY"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:orientation="horizontal" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:paddingLeft="15dip"
android:paddingRight="5dip"
android:text="Z"
android:textStyle="bold" />
<SeekBar
android:id="@+id/rotationZ"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:orientation="horizontal" />
</LinearLayout>
<Button
android:id="@+id/rotatingButton"
android:layout_width="200dip"
android:layout_height="150dip"
android:layout_marginLeft="50dip"
android:layout_marginTop="50dip"
android:text="Rotating Button" />
</LinearLayout>
希望本文所述对大家Android程序设计有所帮助。
来源:http://blog.csdn.net/true100/article/details/51735868


猜你喜欢
- 很多初学者都对C中的指针很迷糊,希望这篇blog能帮助到大家:1.什么是“指针”:在执行C程序的时候,由于我们的数据是存储在内存中的。所以对
- 引言因为写了不少 Spring Security 文章的缘故,所以总是有小伙伴来问松哥:按钮级别的权限怎么实现?甚至有一些看过 vhr 的小
- 在servlet3.0标准之前,是每一个请求对应一个线程。如果此时一个线程出现了高延迟,就会产生阻塞问题,从而导致整个服务出现严重的性能情况
- TextView文本大小自动适配与TextView边距的去除标题太难取了,其实本文主要就是讲如何控制文本大小,让其自动适配宽度,其次我们还需
- QueryWrapper条件构造之apply、last、select场景: 查询数据库限制条数时mysql上的limit使用 Qu
- 一、分布式压测原理如下图(这个图说明的是要一台控制机,然后由这台控制机发压测脚本到每台远程执行机,然后由控制机收集执行机结果)二、修改 Jm
- APP中可能会遇到一种需求,就是将当前所在位置的坐标传到服务器上,今天我提供三种途径去获取经纬度坐标信息,第一种是通过Android API
- 前言用过Spring的人多多少少也都用过@Async注解,至于作用嘛,看注解名,大概能猜出来,就是在方法执行的时候进行异步执行。一、如何使用
- 1 导入需要渐变的图片如果需要实现图片之间的渐变效果,我们需要两张照片,这样才能实现照片1到照片2的渐变。在路径 /res/values/
- 今天在使用Nlog的时候,发现了一个之前没注意的问题。以前,我的app配置文件都是这么写的,当然配置比较多的时候会改用xml。 如
- 本文实例讲述了C#实现农历日历的方法。分享给大家供大家参考。具体实现方法如下://天干 private static
- Java的位操作符用来操作整数基本数据类型中的单个“比特”(bit),即代进制位。而我们知道比特就是0和1,那么,位操作就是对这些数据进行基
- 思维导图一、为什么要学习 DialogFragment你还在用 Dialog 吗?你还在经常烦恼于屏幕翻转的时候,Dialog 的各种奇葩情
- 看完我上一篇文章,「你都理解创建线程池的参数吗?」之后,当遇到这种问题,你觉得你完全能够唬住面试官了,50k轻松到手。殊不知,要是面试官此刻
- 本文实例讲述了C#通过流写入一行数据到文件的方法。分享给大家供大家参考。具体如下:using System;using System.IO;
- 上一篇文章:Android 10 启动分析之Init篇 (一)在前文提到,init进程会在在Trigger 为init的Action中,启动
- jar包打包实现jar包打包可以使用jar指令实现打包,在命令行中输入jar可以查看jar指令的内容 从最后显示的两个示例看出存在两种打包的
- using System; using System.Drawing; using System.Collec
- Spring Security和Shiro的区别相同点1、认证功能2、授权功能3、加密功能4、会话管理5、缓存支持6、rememberMe功
- 本文实例为大家分享了Android实现语音播放与录音的具体代码,供大家参考,具体内容如下项目用到的技术点和亮点语音录音 (单个和列表)语音播