Android的Animator动画(平移,渐隐,旋转,缩放)
工程目录:
Activity
package com.example.animate;import androidx.appcompat.app.ActionBar;
import androidx.appcompat.app.AppCompatActivity;import android.animation.AnimatorSet;
import android.animation.ObjectAnimator;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.ImageView;
import android.widget.TextView;
import android.widget.Toast;public class MainActivity extends AppCompatActivity implements View.OnClickListener{private Button btn_translation,btn_alpha,btn_rotation,btn_scale;private TextView tv;private ImageView iv,iv2;@Overrideprotected void onCreate(Bundle savedInstanceState) {super.onCreate(savedInstanceState);setContentView(R.layout.activity_main);init();}private void init(){ActionBar bar=getSupportActionBar();if(bar!=null)bar.hide();tv=findViewById(R.id.tv);iv=findViewById(R.id.iv);iv2=findViewById(R.id.iv2);btn_translation=findViewById(R.id.btn_translation);btn_alpha=findViewById(R.id.btn_alpha);btn_rotation=findViewById(R.id.btn_rotation);btn_scale=findViewById(R.id.btn_scale);btn_translation.setOnClickListener(this);btn_alpha.setOnClickListener(this);btn_rotation.setOnClickListener(this);btn_scale.setOnClickListener(this);}private void animate(){int x0,y0,x1,y1;int location[]=new int[2],location2[]=new int[2];iv.getLocationInWindow(location);iv2.getLocationInWindow(location2);x0=location[0];y0=location[1];x1=location2[0];y1=location2[1];ObjectAnimator objX=ObjectAnimator.ofFloat(iv,"translationX",0f,x1-x0,0f);ObjectAnimator objY=ObjectAnimator.ofFloat(iv,"translationY",0f,y1-y0,0f);AnimatorSet set=new AnimatorSet();set.playTogether(objX,objY);set.setDuration(1000);set.start();}private void animate2(){ObjectAnimator obj=ObjectAnimator.ofFloat(tv,"alpha",1,0,1);obj.setDuration(1000);obj.start();}private void animate3(){ObjectAnimator obj=ObjectAnimator.ofFloat(tv,"rotation",0,180,270,360);ObjectAnimator objX=ObjectAnimator.ofFloat(tv,"rotationX",0,180,270,360);ObjectAnimator objY=ObjectAnimator.ofFloat(tv,"rotationY",0,180,270,360);AnimatorSet set=new AnimatorSet();set.playSequentially(obj,objX,objY);set.setDuration(2000);set.start();}private void animate4(){ObjectAnimator objX=ObjectAnimator.ofFloat(tv,"scaleX",1,2,3,2,1);ObjectAnimator objY=ObjectAnimator.ofFloat(tv,"scaleY",1,2,3,2,1);AnimatorSet set=new AnimatorSet();set.playSequentially(objX,objY);set.setDuration(1000);set.start();}@Overridepublic void onClick(View v) {switch(v.getId()){case R.id.btn_translation:animate();break;case R.id.btn_alpha:animate2();break;case R.id.btn_rotation:animate3();break;case R.id.btn_scale:animate4();break;}}
}
Layout
<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.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=".MainActivity"><LinearLayoutandroid:layout_width="match_parent"android:layout_height="match_parent"android:orientation="vertical"><Buttonandroid:id="@+id/btn_translation"android:layout_width="match_parent"android:layout_height="wrap_content"android:textAllCaps="false"android:text="Translation" /><Buttonandroid:id="@+id/btn_alpha"android:layout_width="match_parent"android:layout_height="wrap_content"android:textAllCaps="false"android:text="Alpha" /><Buttonandroid:id="@+id/btn_rotation"android:layout_width="match_parent"android:layout_height="wrap_content"android:textAllCaps="false"android:text="Rotation" /><Buttonandroid:id="@+id/btn_scale"android:layout_width="match_parent"android:layout_height="wrap_content"android:text="Scale"android:textAllCaps="false" /><TextViewandroid:id="@+id/tv"android:layout_width="70sp"android:layout_height="70sp"android:layout_gravity="center"android:background="#90CAF9"android:text="" /><RelativeLayoutandroid:layout_width="match_parent"android:layout_height="match_parent"><LinearLayoutandroid:layout_width="match_parent"android:layout_height="wrap_content"android:layout_alignParentBottom="true"android:orientation="vertical"><ImageViewandroid:id="@+id/iv"android:layout_width="30sp"android:layout_height="30sp"android:src="@drawable/icon" /><ImageViewandroid:id="@+id/iv2"android:layout_width="30sp"android:layout_height="30sp"android:layout_marginTop="50sp"android:layout_gravity="right"android:src="@drawable/icon" /></LinearLayout></RelativeLayout></LinearLayout></androidx.constraintlayout.widget.ConstraintLayout>
Android的Animator动画(平移,渐隐,旋转,缩放)相关推荐
- android属性动画缩放和平移同时,Android 实现属性动画平移,旋转,缩放,渐变 《H》...
以下代码直接使用点击事件调用即可 平移 ObjectAnimator translationX = new ObjectAnimator().ofFloat(myyuan,"translat ...
- Android中的动画详析-kotlin的demo
Android中的动画可以分为三种,View动画,帧动画,以及属性动画,实际上帧动画也是View动画的一种,只不过二者表现形式不同,View动画是通过不断地对场景里的动画做图像转换从而产生动画效果是一 ...
- android淡入淡出动画循环,Android应用开发之淡入淡出、缩放、旋转、平移、组合动画效果代码实现...
本文将带你了解Android应用开发Android动画开发之淡入淡出.缩放.旋转.平移.组合动画效果代码实现,希望本文对大家学Android有所帮助. 1.activity_main.xml文件 an ...
- transform(平移、旋转、缩放、3d转换)、渐变、动画笔记
文章目录 HTML5 1. HTML5新增标签 2. 表单属性--交互表单属性 CSS3 1. 选择器 1.1 属性选择器 1.2 结构伪类选择器 1.3 伪元素选择器 2. css属性 2.1 平面 ...
- Android 绘图基础:Bitmap(位图)与Matrix(矩阵)实现图片5种操作(平移、旋转、错切、缩放、对称)
Android的Matrix利用数学原理实现图片平移.旋转等操作详解 很庆幸自己的线性代数学的还可以,理解Matrix的矩阵变换完全没有问题.Matrix矩阵实现图片的平移旋转等操作涉及到线性代数问题 ...
- 前端学习:jQuery--轮播图,旋转缩放平移动画,仿华为商城案例
1.火狐浏览器超好用的网页翻译插件 火狐浏览器超好用的网页翻译插件_m0_59805351的博客-CSDN博客_火狐翻译插件哪个好学习目标:自主安装火狐浏览器网页翻译插件学习内容:提示:这里可以添加要 ...
- css3平移、旋转、倾斜、缩放、动画效果的实现
HTML代码: <!DOCTYPE html> <html lang="en"> <head><meta charset="UT ...
- Android View 通过平移、旋转、缩放后,顶点映射
View 通过如下操作,在平移.旋转.缩放后,其本身的 left.top.right.bottom.width.height是没有变化的. 平移:setTranslationX(), setTrans ...
- android旋转动画惯性,Android实现对图片放大、平移和旋转的功能
先来看看要实现的效果图 在讲解中,需要大家提前了解一些关于图片绘制的原理的相关知识. 关于实现的流程 1.自定义View 2.获得操作图片的Bitmap 3.复写View的onTouchEvent() ...
最新文章
- VS Code配置PHP XDebug
- ASCII码对照表(不可见字符)
- 什么是随机存取_SRAM存储器是什么存储器
- Loader之一:基本原理
- linux怎么进入文件夹_Linux基础命令《上》
- php 变量 换行,php去除换行符的方法小结(PHP_EOL变量的使用)_PHP教程
- 没有bug队——加贝——Python 49,50
- react-native ES5与ES6写法对照表
- 解决ubuntu的firefox上网速度慢[转]
- 金庸群侠传1android,96版金庸群侠传1手机版
- ISO9000:2000 质量管理八大原则
- 360,手机助手的功能,既然有如此二面性?
- python 进化树_进化树专题(七)| 进化树与不完全谱系分选
- Redis学习之Master/Salve十一
- Linux LVM全面实践
- JSjavascript获取B站bilibili哔哩哔哩分P播放列表并以excel文件保存本地
- 纯css实现翻书效果
- RateLimiter实现限流
- 【RF预测】基于matlab随机森林算法数据回归预测【含Matlab源码 2047期】
- python库numpy使用技巧(二)——随机抽取二维矩阵中多行或多列
热门文章
- 任何性能指标越界或造成 APP 崩溃,优酷通用性能测试一招搞定
- 数据科学家们会被 AutoML 代替吗?
- 疫情肆虐下,程序员用代码告诉你为什么千万不要出门!
- 国际顶级学界和工业界大咖云集、AIoT 实训营,你不可错过的嵌入式 AI 盛会!...
- 200 行代码解读国产数据库阿里 OceanBase 的速度源头!| CSDN 博文精选
- 谁说 Vim 不好用?
- 绿洲因涉嫌抄袭下架;Facebook 泄露 4.19 亿条用户数据;Go 1.13 发布 | 极客头条...
- 为前端工程之崛起而编程!
- 京东金融 App 收集隐私?开源库程序员不背锅!
- 新鲜出炉,Python 告诉你程序员最关注的技术竟然是……