Android控件Tween动画(补间动画)实现方法示例
发布时间 - 2026-01-11 02:46:26 点击率:次本文实例讲述了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相关内容感兴趣的读者可查看本站专题:《Android开发动画技巧汇总》、《Android开发入门与进阶教程》、《Android视图View技巧总结》、《Android编程之activity操作技巧总结》、《Android文件操作技巧汇总》、《Android资源操作技巧汇总》及《Android控件用法总结》
希望本文所述对大家Android程序设计有所帮助。
# Android
# 控件
# Tween动画
# 补间动画
# Android Studio实现补间动画
# Android动画系列之帧动画和补间动画的示例代码
# Android动画学习笔记之补间动画
# Android补间动画基本使用(位移、缩放、旋转、透明)
# Android旋转、平移、缩放和透明度渐变的补间动画
# android 帧动画
# 属性动画的简单总结
# Android帧动画、补间动画、属性动画用法详解
# Android动画之补间动画(Tween Animation)基础学习
# Android动画之补间动画(Tween Animation)实例详解
# Android Studio实现简单补间动画
# 操作技巧
# 下午
# 进阶
# 相关内容
# 感兴趣
# 给大家
# 拖动
# 更多关于
# 所述
# 程序设计
# 画中
# 讲述了
# Bundle
# onCreate
# void
# savedInstanceState
# layout
# setContentView
# super
# Override
相关栏目:
【
网站优化151355 】
【
网络推广146373 】
【
网络技术251813 】
【
AI营销90571 】
相关推荐:
Win11怎么设置默认图片查看器_Windows11照片应用关联设置
Laravel怎么使用Blade模板引擎_Laravel模板继承与Component组件复用【手册】
JavaScript如何实现音频处理_Web Audio API如何工作?
Laravel如何处理异常和错误?(Handler示例)
,网页ppt怎么弄成自己的ppt?
C语言设计一个闪闪的圣诞树
如何在景安云服务器上绑定域名并配置虚拟主机?
PHP的CURL方法curl_setopt()函数案例介绍(抓取网页,POST数据)
利用python获取某年中每个月的第一天和最后一天
如何在香港服务器上快速搭建免备案网站?
Laravel如何升级到最新的版本_Laravel版本升级流程与兼容性处理
Laravel广播系统如何实现实时通信_Laravel Reverb与WebSockets实战教程
Laravel Seeder怎么填充数据_Laravel数据库填充器的使用方法与技巧
Laravel队列由Redis驱动怎么配置_Laravel Redis队列使用教程
利用JavaScript实现拖拽改变元素大小
大学网站设计制作软件有哪些,如何将网站制作成自己app?
教你用AI将一段旋律扩展成一首完整的曲子
如何快速搭建高效WAP手机网站吸引移动用户?
香港服务器部署网站为何提示未备案?
Laravel怎么写单元测试_PHPUnit在Laravel项目中的基础测试入门
Laravel API资源(Resource)怎么用_格式化Laravel API响应的最佳实践
在线制作视频网站免费,都有哪些好的动漫网站?
Laravel怎么返回JSON格式数据_Laravel API资源Response响应格式化【技巧】
文字头像制作网站推荐软件,醒图能自动配文字吗?
WEB开发之注册页面验证码倒计时代码的实现
Laravel如何使用Sanctum进行API认证?(SPA实战)
Laravel如何安装Breeze扩展包_Laravel用户注册登录功能快速实现【流程】
使用C语言编写圣诞表白程序
php结合redis实现高并发下的抢购、秒杀功能的实例
Laravel distinct去重查询_Laravel Eloquent去重方法
Laravel中的withCount方法怎么高效统计关联模型数量
微博html5版本怎么弄发超话_超话进入入口及发帖格式要求【教程】
jQuery中的100个技巧汇总
香港服务器租用费用高吗?如何避免常见误区?
Midjourney怎样加参数调细节_Midjourney参数调整技巧【指南】
关于BootStrap modal 在IOS9中不能弹出的解决方法(IOS 9 bootstrap modal ios 9 noticework)
公司网站制作价格怎么算,公司办个官网需要多少钱?
Laravel如何处理JSON字段的查询和更新_Laravel JSON列操作与查询技巧
Laravel怎么实现搜索高亮功能_Laravel结合Scout与Algolia全文检索【实战】
logo在线制作免费网站在线制作好吗,DW网页制作时,如何在网页标题前加上logo?
Laravel怎么为数据库表字段添加索引以优化查询
Bootstrap整体框架之CSS12栅格系统
使用spring连接及操作mongodb3.0实例
如何用虚拟主机快速搭建网站?详细步骤解析
品牌网站制作公司有哪些,买正品品牌一般去哪个网站买?
Laravel任务队列怎么用_Laravel Queues异步处理任务提升应用性能
深圳防火门网站制作公司,深圳中天明防火门怎么编码?
如何在七牛云存储上搭建网站并设置自定义域名?
如何续费美橙建站之星域名及服务?
html5audio标签播放结束怎么触发事件_onended回调方法【教程】

