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
0
投稿
猜你喜欢
- Spring 是一个开源框架,是为了解决企业应用程序开发复杂性而创建的。框架的主要优势之一就是其分层架构,分层架构允许您选择使用哪一个组件,
- SpringBoot找不到javax.servlet.Filter的问题新创建一个SpringBoot项目,编译时出现了找不到javax.s
- 在定义一个Rest接口时通常会利用GET、POST、PUT、DELETE来实现数据的增删改查;这几种方式有的需要传递参数,后台开发人员必须对
- 本文实例讲述了Android实现EditText中添加和删除bitmap的方法。分享给大家供大家参考,具体如下:SpannableStrin
- Http通信概述Http通信主要有两种方式POST方式和GET方式。前者通过Http消息实体发送数据给服务器,安全性高,数据传输大小没有限制
- Spring中有个RestTemplate类用来发送HTTP请求很方便,本文分享一个SpringBoot发送POST请求并接收返回数据的例子
- 哈喽大家好啊,我是Hydra。Spring作为项目中不可缺少的底层框架,提供的最基础的功能就是bean的管理了。bean的注入相信大家都比较
- 方法一:<uses-permission android:name="android.permission.WAKE_LOC
- DrawingContext比较类似WinForm中的Graphics 类,是基础的绘图对象,用于绘制各种图形,它主要API有如下
- Java 利用poi把数据库中数据导入Excel效果:使用时先把poi包导入工程的path,注意只需要导入poi包即可,下载后有三个jar包
- Spring Security OAuth 默认提供OAuth2.0 的四大基本授权方式(authorization_code\implic
- 下面是利用Java实现读写文件功能的示例代码读文件TextRead.javaimport java.io.BufferedReader;im
- 本文实例为大家分享了java判断某个点是否在所画范围内的具体代码,供大家参考,具体内容如下IsPtInPoly.javapackage co
- 我object != null要避免很多NullPointerException。有什么替代方法:if (someobject != nul
- Java 虚拟机在执行Java程序的过程中会把它所管理的内存划分为若干个不同的数据区域,这些区域都有各自的用途,如图所示:程序计数器程序计数
- 直接用idea clean install 进行打包maven项目时,如果没有进行设置会把测试文件也打包进去。想要忽略test文件将Mave
- 本文实例为大家分享了Java实现统计字符串出现次数的具体代码,供大家参考,具体内容如下需求:健盘录入一个字符串,要求统计字符串中每个字符串出
- 作为一个合格的开发人员,对项目进行管理自然必不可少。今天就给各位看客介绍一下如何用git将自己的AS项目上传到码云。
- 多线程编程多线程编程模式.NET 中,有三种异步编程模式,分别是基于任务的异步模式(TAP)、基于事件的异步模式(EAP)、异步编程模式(A
- 具体可见http://developer.android.com/tools/debugging/ddms.html。 DDMS为IDE和e