Android studio 动画---补间动画

article/2025/11/7 23:51:12

1、新建文件。【注意:文件名只能命名为anim】

 2、新建文件

3、在新建的文件中添加代码:【以下代码仅供参考】

3.1、改变动画的透明度:

<?xml version="1.0" encoding="utf-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android"><alphaandroid:interpolator="@android:anim/linear_interpolator"android:repeatMode="reverse"android:repeatCount="infinite"android:duration="1000"  //持续时间android:fromAlpha="1.0"android:toAlpha="0.0"/>
</set>

3.2、动画旋转 :

<?xml version="1.0" encoding="utf-8"?>
<!--suppress ALL -->
<set xmlns:android="http://schemas.android.com/apk/res/android">
<!--    反向旋转--><rotateandroid:fromDegrees="0"android:toDegrees="360" //旋转360°android:pivotX="50%"android:pivotY="50%"android:repeatCount="-1"android:repeatMode="reverse"  android:duration="1000"/><!--    正向旋转-->
<!--    <rotate-->
<!--    android:fromDegrees="0"-->
<!--    android:toDegrees="360"-->  
<!--    android:pivotX="50%"-->
<!--    android:pivotY="50%"-->
<!--    android:repeatCount="-1"-->
<!--    android:repeatMode="restart"-->
<!--    android:duration="1000"/>--></set>

 3.3、动画缩放:

<?xml version="1.0" encoding="utf-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android"><scaleandroid:fromXScale="1.0"android:fromYScale="1.0"android:toXScale="0.5"android:toYScale="0.5"android:pivotX="50%"android:pivotY="50%"android:repeatMode="reverse"android:repeatCount="infinite"android:duration="3000"/>
</set>

3.4、动画平移:

<?xml version="1.0" encoding="utf-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android"><translateandroid:fromXDelta="0.0"android:fromYDelta="0.0"android:toXDelta="100"android:toYDelta="0.0"android:repeatCount="infinite"android:repeatMode="reverse"android:duration="4000"/>
</set>

 Java代码如下:【仅供参考】

//这里用到了多个按钮,直接实现OnClickListener()方法
public class MainActivity extends AppCompatActivity implements View.OnClickListener {private ImageView ima;private Button btn1;private Button btn2;private Button btn3;private Button btn4;private Button btn5;@Overrideprotected void onCreate(Bundle savedInstanceState) {super.onCreate(savedInstanceState);setContentView(R.layout.activity_main);initView();}private void initView() {ima = (ImageView) findViewById(R.id.ima);btn1 = (Button) findViewById(R.id.btn1);btn2 = (Button) findViewById(R.id.btn2);btn3 = (Button) findViewById(R.id.btn3);btn4 = (Button) findViewById(R.id.btn4);btn5 = (Button) findViewById(R.id.btn5);btn1.setOnClickListener(this);btn2.setOnClickListener(this);btn3.setOnClickListener(this);btn4.setOnClickListener(this);btn5.setOnClickListener(this);}@Overridepublic void onClick(View v) {switch (v.getId()){case R.id.btn1:               
Animation alpha = AnimationUtils.loadAnimation(this,R.anim.alpha_animation);//透明度,渐变ima.startAnimation(alpha);//开启动画break;case R.id.btn2:
Animation rotate = AnimationUtils.loadAnimation(this,R.anim.rotate_animation);//旋转ima.startAnimation(rotate);break;case R.id.btn3:
Animation translate = AnimationUtils.loadAnimation(this,R.anim.translate_animation);//平移ima.startAnimation(translate);break;case R.id.btn4:
Animation scale =AnimationUtils.loadAnimation(this,R.anim.scale_animation);//缩放ima.startAnimation(scale);break;case R.id.btn5:ima.clearAnimation();//动画暂停break;}}
}

效果演示参考如下链接:

Android studio 补间动画显示-CSDN


http://chatgpt.dhexx.cn/article/sZVQSpXe.shtml

相关文章

动画三部曲--补间动画

图片从慢慢退出&#xff0c;过程中通过缩放、渐变等实现动画效果 将缩放的参数写入xml 中&#xff0c;translate_animation.xml <translatexmlns:android"http://schemas.android.com/apk/res/android"android:fromXDelta"0"android:fromYDelta"…

Android 补间动画原理

这段时间项目中用到了动画&#xff0c;所以趁热打铁&#xff0c;看看动画原理 补间动画 使用举例 TranslateAnimation translateAnim new TranslateAnimation(0, 100, 0, 100);translateAnim.setDuration(1000);translateAnim.setFillAfter(true);testBut.startAnimation(t…

补间动画和逐帧动画

补间动画 补间&#xff08;Tween&#xff09;动画通过对View进行一系列的图形变换来实现动画效果&#xff0c;其中图像变换包括平移、缩放、旋转、改变透明度等。补间动画最常用的方式是通过XML文件定义动画。 透明度渐变动画&#xff08;AlphaAnimation&#xff09; 主要通…

Android 动画—补间动画

帧动画是通过连续播放图片来模拟动画效果&#xff0c;而补间动画开发者只需指定动画开始&#xff0c;以及动画结束"关键帧"&#xff0c;而动画变化的"中间帧"则由系统计算并补齐&#xff01; 1.补间动画的分类和Interpolator Andoird所支持的补间动画效果…

【Android】补间动画用法最全详解

本文目录 补间动画概述和分类各类补间动画实现xml实现补间动画透明度动画-AlphaAnimation缩放动画-ScaleAnimation位移动画-TranslateAnimation旋转动画-RotateAnimation动画组合-AnimationSet 代码实现补间动画透明度动画&#xff08;AlphaAnimation&#xff09;缩放动画&…

补间动画详解一 基类Animation

补间动画(Tween animation)是通过在两个关键帧之间补充渐变的动画效果来实现的。 Android系统提供了四个补间动画的类,分别是AlphaAnimation、RotateAnimation、ScaleAnimation和TranslateAnimation,另外还有一个能够把多个动画组合起来的AnimationSet类,这些类都有一个共…

Android动画之补间动画

Android动画之补间动画 和上面一章学的帧动画不同&#xff0c;帧动画 是通过连续播放图片来模拟动画效果&#xff0c;而补间动画开发者只需指定动画开始&#xff0c;以及动画结束"关键帧"&#xff0c; 而动画变化的"中间帧"则由系统计算并补齐&#xff01…

使用Gstreamer处理RTSP视频流

文章目录 RTSP视频流处理方法1. Gstreamer整体框架1.1 Media Applications1.2 Core Framework1.3 Plugins 2. Gstreamer组件2.1 Element2.2 Pad2.3 Bin和Pipeline 3. gstreamer tools3.1 gst-inspect-1.03.2 gst-launch-1.0 4. 参考链接 RTSP视频流处理方法 这里使用Gstreamer…

GStreamer基础教程02——GStreamer概念

上一个教程演示了如何自动生成一个pipeline。这次我们打算用一个个element来手动搭建一个pipeline。我们这个教程会演示&#xff1a; 1. 什么是GStreamer的element以及如何建立一个element 2. 如何在element直接建立连接 3. 如何客制化element的行为 4. 如何监视总线上的错…

GStreamer功能详解

参考&#xff1a;https://blog.csdn.net/tx3344/article/details/7497434 参考&#xff1a;https://thebigdoc.readthedocs.io/en/latest/gstreamer/gst-concept.html 参考&#xff1a;https://blog.csdn.net/sdjhs/article/details/51444934 什么是GStreamer&#xff1f; …

基于gstreamer的rtsp推送和转发

基于gstreamer的rtsp推送和转发 一、配置gstreamer环境二、安装gstreamer-rtsp-server三、读取usb摄像头并推rtsp流四、转发rtsp 前段时间因为实验室项目要求&#xff0c;需要读取摄像头并推rtsp流&#xff0c;由于我们实验室不是做与之相关的工作&#xff0c;所以并没有什么参…

深入浅出gstreamer开发

Gstreamer解决什么问题&#xff1f; — 上层接口和应用方式的 相对稳定 与底层接口、平台环境的 多样化 。例如&#xff1a; codec 不同种类不同实现&#xff0c;音视频处理不同&#xff0c;硬件输入、输出、采集播放不同&#xff0c;芯片不同&#xff0c;操作系统不同。 — 通…

【GStreamer 】3-1 gstreamer插件之 videotestsrc 介绍

目录 ​编辑 1、简介 2、videotestsrc 3、videotestsrc 不同pattern参数测试罗列 3.1 (0): smpte - SMPTE 100% color bars 3.2 (1): snow - Random (television snow) 3.3 (2): black - 100% Black ​编辑 3.4 checkers 方块 ​编辑 3.5 几何图形 4、videotestsrc…

Gstreamer概述

1、什么是GStreamer GStreamer 是用来构建流媒体应用的开源多媒体框架(framework)&#xff0c;其基本设计思想来自于俄勒冈(Oregon)研究生学院有关视频管道的创意, 同时也借鉴了DirectShow的设计思想。其目标是要简化音/视频应用程序的开发&#xff0c;已经能够被用来处理像 M…

gstreamer简介

常用 gchar * caps_string gst_caps_to_string (new_selected_caps); g_free (caps_string); 需要弄懂的问题 tunnel tee queue 最后列一下Gstreamer中常见的时间宏&#xff0c;注意Gstreamer中的时间单位是&#xff1a;纳秒 #define G_USEC_PER_SEC 1000000 #define GST_S…

Gstreamer基础知识介绍

由于deepstream是基于gstreamer的&#xff0c;所以要想在deepstream上做拓展&#xff0c;需要对gstreamer有一定的认识。以下主要介绍Gstreamer整体框架和Gstreamer基础概念。 一、Gstreamer整体框架 gstreamer是一个用于开发流式多媒体应用的开源框架。本身这个框架是为了更…

【GStreamer 】1-扫盲介绍

从历史的角度来看&#xff0c;Linux 在多媒体方面已经远远落后于其它的操作系统。微软的Windows和苹果的MacOS它们对多媒体设备、多媒体创作、播放和实时处理等方面已经有了很好的支持。另一方面&#xff0c;Linux对多媒体应用的综合贡献比较少&#xff0c;这也使得Linux很难在…

详细的GStreamer开发教程

详细的GStreamer开发教程 文章目录 详细的GStreamer开发教程1. 什么是GStreamer&#xff1f;2. GStreamer架构2.1 Media Applications2.2 Core Framework2.3 Plugins 3. GStreamer组件3.1 Element创建一个 GstElement 3.2 箱柜&#xff08;bin&#xff09;元件的状态 3.3 衬垫&…

gstreamer(一)入门和概述

一&#xff0e;概述 在音视频领域接触最多实现的方案通常是通过ffmpeg&#xff08;PC和sever端居多&#xff09;或者硬件厂家的的SDK实现特定硬件的编解码功能&#xff08;机顶盒&#xff0c;电视等嵌入式设备&#xff09;。这里我们介绍一个在国内不太常用的解决方案----gstr…

二、什么是GStreamer

GStreamer是一个用于创建流媒体应用程序的框架。基本的设计来自俄勒冈研究生院的视频管道&#xff0c;还有一些来自DirectShow的想法。 GStreamer的开发框架使编写任何类型的流媒体应用程序成为可能。GStreamer框架旨在使编写处理音频或视频或两者同时处理的应用程序变得容易。…