Android控件Tween动画(补间动画)实现方法示例
作者:迟做总比不做强 时间:2021-12-31 17:46:39
本文实例讲述了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
标签:Android,Tween动画,补间动画
![](/images/zang.png)
![](/images/jiucuo.png)
猜你喜欢
C# XML操作类分享
2022-02-16 03:22:03
使用注解@Validated和BindingResult对入参进行非空校验方式
2022-09-16 11:30:44
![](https://img.aspxhome.com/file/2023/5/66215_0s.png)
详解C#中HashTable的用法
2023-07-17 04:42:07
SpringCloud Alibaba项目实战之nacos-server服务搭建过程
2022-02-28 02:43:26
![](https://img.aspxhome.com/file/2023/2/85542_0s.jpg)
Unity3D使用Shader实现腐蚀消失
2022-01-07 20:57:59
![](https://img.aspxhome.com/file/2023/1/89751_0s.gif)
Android实现双层ViewPager嵌套
2021-12-23 02:35:52
![](https://img.aspxhome.com/file/2023/4/96804_0s.gif)
Java线程的基本概念
2022-05-20 16:30:22
Java Swing JComboBox下拉列表框的示例代码
2022-09-16 00:24:50
![](https://img.aspxhome.com/file/2023/6/79886_0s.gif)
SpringMVC配置多个properties文件之通配符解析
2021-10-18 02:19:02
![](https://img.aspxhome.com/file/2023/8/81898_0s.png)
Java class文件格式之特殊字符串_动力节点Java学院整理
2022-02-11 14:45:59
详解使用Spring AOP和自定义注解进行参数检查
2021-11-27 00:06:49
![](https://img.aspxhome.com/file/2023/1/70261_0s.jpg)
基于list stream: reduce的使用实例
2021-07-21 06:54:52
Mybatis查询时,区分大小写操作
2021-08-11 14:10:54
Java 可视化垃圾回收_动力节点Java学院整理
2023-02-19 07:03:55
![](https://img.aspxhome.com/file/2023/1/88181_0s.png)
C#抓取当前屏幕并保存为图片的方法
2023-09-27 08:39:43
Java中Scanner类与BufferReader类的不同点(非常详细)
2023-07-07 01:21:18
Java 线程池原理深入分析
2023-01-30 19:59:43
![](https://img.aspxhome.com/file/2023/7/66227_0s.png)
Java多线程的临界资源问题解决方案
2021-12-29 07:44:35
Java 中的垃圾回收机制详解
2023-01-11 19:32:34
![](https://img.aspxhome.com/file/2023/2/67162_0s.png)
如何解决springmvc文件下载,内容损坏的问题
2023-10-11 07:12:10
![](https://img.aspxhome.com/file/2023/9/89959_0s.png)