【Android】属性动画(83/100)
核心动画代码如下:
private ObjectAnimator alphaAnim, translateAnim, scaleAnim, rotateAnim; // 声明四个属性动画对象
private void initObjectAnim() {
// 构造一个在透明度上变化的属性动画
alphaAnim = ObjectAnimator.ofFloat(imageView, "alpha", 1f, 0.1f, 1f);
// 构造一个在横轴上平移的属性动画
translateAnim = ObjectAnimator.ofFloat(imageView, "translationX", 0f, -200f, 0f, 200f, 0f);
// 构造一个在纵轴上缩放的属性动画
scaleAnim = ObjectAnimator.ofFloat(imageView, "scaleY", 1f, 0.5f, 1f);
// 构造一个围绕中心点旋转的属性动画
rotateAnim = ObjectAnimator.ofFloat(imageView, "rotation", 0f, 360f, 0f);
}
效果控制如下:
private String[] objectArray = {"灰度动画", "平移动画", "缩放动画", "旋转动画", "裁剪动画"};
// 播放指定类型的属性动画
@RequiresApi(api = Build.VERSION_CODES.JELLY_BEAN_MR2)
private void playObjectAnim(int type) {
ObjectAnimator anim = null;
if (type == 0) { // 灰度动画
anim = alphaAnim;
} else if (type == 1) { // 平移动画
anim = translateAnim;
} else if (type == 2) { // 缩放动画
anim = scaleAnim;
} else if (type == 3) { // 旋转动画
anim = rotateAnim;
} else if (type == 4) { // 裁剪动画
int width = imageView.getWidth();
int height = imageView.getHeight();
// 构造一个从四周向中间裁剪的属性动画
ObjectAnimator clipAnim = ObjectAnimator.ofObject(imageView, "clipBounds",
new RectEvaluator(), new Rect(0, 0, width, height),
new Rect(width / 3, height / 3, width / 3 * 2, height / 3 * 2),
new Rect(0, 0, width, height));
anim = clipAnim;
}
if (anim != null) {
anim.setDuration(3000); // 设置动画的播放时长
anim.start(); // 开始播放属性动画
}
}
补充xml布局:
<?xml version="1.0" encoding="utf-8"?>
<android.support.constraint.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".activity.ObjectAnimActivity">
<TextView
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
android:id="@+id/tv_label"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:paddingLeft="5dp"
android:text="请选择:"
android:textColor="@color/black"
android:textSize="17sp"
/>
<Spinner
app:layout_constraintStart_toEndOf="@id/tv_label"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintEnd_toEndOf="parent"
android:id="@+id/spinner"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:spinnerMode="dropdown" />
<ImageView
android:id="@+id/iv_origin"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@id/tv_label"
android:layout_width="match_parent"
android:layout_height="300dp"
android:src="@mipmap/ic_img05"
android:scaleType="fitXY"
android:layout_margin="10dp"
/>
</android.support.constraint.ConstraintLayout>
在最初的android动画框架里有许多的缺陷,后来随着android系统版本的迭代陆陆续续修复了。这些动画框架可能都用不到了。但参考学习还是不错的。
自研产品推荐
历时一年半多开发终于smartApi-v1.0.0版本在2023-09-15晚十点正式上线
smartApi是一款对标国外的postman的api调试开发工具,由于开发人力就作者一个所以人力有限,因此v1.0.0版本功能进行精简,大功能项有:
- api参数填写
- api请求响应数据展示
- PDF形式的分享文档
- Mock本地化解决方案
- api列表数据本地化处理
- 再加上UI方面的打磨
为了更好服务大家把之前的公众号和软件激活结合,如有疑问请大家反馈到公众号即可,下个版本30%以上的更新会来自公众号的反馈。
嗯!先解释不上服务端原因,API调试工具的绝大多数时候就是一个数据模型、数据处理、数据模型理解共识的问题解决工具,所以作者结合自己十多年开发使用的一些痛点来打造的,再加上服务端开发一般是面向企业的,作者目前没有精力和时间去打造企业服务。再加上没有资金投入所以服务端开发会滞后,至于什么时候会进行开发,这个要看募资情况和用户反馈综合考虑。虽然目前国内有些比较知名的api工具了,但作者使用后还是觉得和实际使用场景不符。如果有相关吐槽也可以在作者的公众号里反馈蛤!
下面是一段smartApi使用介绍:
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· DeepSeek 开源周回顾「GitHub 热点速览」
· 物流快递公司核心技术能力-地址解析分单基础技术分享
· .NET 10首个预览版发布:重大改进与新特性概览!
· AI与.NET技术实操系列(二):开始使用ML.NET
· 单线程的Redis速度为什么快?