《android 的四中动画效果》

2024-01-12 18:10
文章标签 android 效果 动画 四中

本文主要是介绍《android 的四中动画效果》,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!

2019独角兽企业重金招聘Python工程师标准>>> hot3.png

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"xmlns:tools="http://schemas.android.com/tools"android:layout_width="match_parent"android:layout_height="match_parent"android:paddingBottom="@dimen/activity_vertical_margin"android:paddingLeft="@dimen/activity_horizontal_margin"android:paddingRight="@dimen/activity_horizontal_margin"android:paddingTop="@dimen/activity_vertical_margin"tools:context=".MainActivity" ><Buttonandroid:id="@+id/button1"android:layout_width="wrap_content"android:layout_height="wrap_content"android:layout_alignParentBottom="true"android:layout_centerHorizontal="true"android:text="Button" /><Buttonandroid:id="@+id/button2"android:layout_width="wrap_content"android:layout_height="wrap_content"android:layout_above="@+id/button1"android:layout_alignLeft="@+id/button1"android:layout_marginBottom="20dp"android:text="Button" /><Buttonandroid:id="@+id/button3"android:layout_width="wrap_content"android:layout_height="wrap_content"android:layout_above="@+id/button2"android:layout_alignLeft="@+id/button2"android:layout_marginBottom="16dp"android:text="Button" /><Buttonandroid:id="@+id/button4"android:layout_width="wrap_content"android:layout_height="wrap_content"android:layout_above="@+id/button3"android:layout_alignRight="@+id/button3"android:layout_marginBottom="38dp"android:text="Button" /><ImageViewandroid:id="@+id/imageView1"android:layout_width="wrap_content"android:layout_height="wrap_content"android:layout_alignLeft="@+id/button4"android:layout_alignParentTop="true"android:layout_marginTop="26dp"android:src="@drawable/ic_launcher" />
</RelativeLayout>

这是布局文件

package com.example.move;
import android.os.Bundle;
import android.app.Activity;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.animation.AlphaAnimation;
import android.view.animation.Animation;
import android.view.animation.AnimationSet;
import android.view.animation.RotateAnimation;
import android.view.animation.ScaleAnimation;
import android.view.animation.TranslateAnimation;
import android.widget.Button;
import android.widget.ImageView;
public class MainActivity extends Activity {private Button alphaBut;//淡静淡出private ImageView imageView;private Button rotateBut;//旋转private Button scaleBut;//缩小也可以放大private Button tranBut;//移动@Overrideprotected void onCreate(Bundle savedInstanceState) {super.onCreate(savedInstanceState);setContentView(R.layout.activity_main);alphaBut=(Button) findViewById(R.id.button1);rotateBut=(Button) findViewById(R.id.button2);scaleBut=(Button) findViewById(R.id.button3);tranBut=(Button) findViewById(R.id.button4);imageView=(ImageView) findViewById(R.id.imageView1);alphaBut.setOnClickListener(new AlphaButoon());rotateBut.setOnClickListener(new RotateButoon());scaleBut.setOnClickListener(new ScaleButoon());tranBut.setOnClickListener(new TranButoon());}class TranButoon implements OnClickListener{@Overridepublic void onClick(View arg0) {AnimationSet animationSet=new AnimationSet(true);Animation animation=new TranslateAnimation(Animation.RELATIVE_TO_SELF, 0.5f, Animation.RELATIVE_TO_SELF, 0.5f, Animation.RELATIVE_TO_SELF, 0.5f, Animation.RELATIVE_TO_SELF, 0.5f);animation.setDuration(2000);animationSet.addAnimation(animation);imageView.startAnimation(animationSet);tranBut.startAnimation(animationSet);}}class ScaleButoon implements OnClickListener{@Overridepublic void onClick(View arg0) {AnimationSet animationSet=new AnimationSet(true);Animation animation=new ScaleAnimation(1, 0.5f, 1, 0.5f, Animation.RELATIVE_TO_SELF, 0.5f, Animation.RELATIVE_TO_SELF,0.5f);animation.setDuration(2000);animationSet.addAnimation(animation);imageView.startAnimation(animationSet);scaleBut.startAnimation(animationSet);}}class AlphaButoon implements OnClickListener{@Overridepublic void onClick(View arg0) {AnimationSet animationSet=new AnimationSet(true);Animation animation=new AlphaAnimation(0, 1);animation.setDuration(2000);animationSet.addAnimation(animation);imageView.startAnimation(animationSet);alphaBut.startAnimation(animationSet);}}class RotateButoon implements OnClickListener{@Overridepublic void onClick(View arg0) {AnimationSet animationSet=new AnimationSet(true);//0-360从那个角度转到那个角度,X轴的参考值,0,5f百分之50,Y轴的参考值,0,5f百分之50Animation rotate=new RotateAnimation(0, 360,Animation.RELATIVE_TO_PARENT,0.5f,Animation.RELATIVE_TO_PARENT,0.5f);Animation alpha=new AlphaAnimation(0, 1);rotate.setDuration(2000);animationSet.addAnimation(rotate);alpha.setDuration(100);animationSet.addAnimation(alpha);imageView.startAnimation(animationSet);rotateBut.startAnimation(animationSet);}}
}

主函数

转载于:https://my.oschina.net/u/1269023/blog/287488

这篇关于《android 的四中动画效果》的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!


原文地址:https://blog.csdn.net/weixin_33736832/article/details/92088534
本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.chinasem.cn/article/598725

相关文章

Android实现打开本地pdf文件的两种方式

《Android实现打开本地pdf文件的两种方式》在现代应用中,PDF格式因其跨平台、稳定性好、展示内容一致等特点,在Android平台上,如何高效地打开本地PDF文件,不仅关系到用户体验,也直接影响... 目录一、项目概述二、相关知识2.1 PDF文件基本概述2.2 android 文件访问与存储权限2.

Android Studio 配置国内镜像源的实现步骤

《AndroidStudio配置国内镜像源的实现步骤》本文主要介绍了AndroidStudio配置国内镜像源的实现步骤,文中通过示例代码介绍的非常详细,对大家的学习或者工作具有一定的参考学习价值,... 目录一、修改 hosts,解决 SDK 下载失败的问题二、修改 gradle 地址,解决 gradle

在Android平台上实现消息推送功能

《在Android平台上实现消息推送功能》随着移动互联网应用的飞速发展,消息推送已成为移动应用中不可或缺的功能,在Android平台上,实现消息推送涉及到服务端的消息发送、客户端的消息接收、通知渠道(... 目录一、项目概述二、相关知识介绍2.1 消息推送的基本原理2.2 Firebase Cloud Me

Android中Dialog的使用详解

《Android中Dialog的使用详解》Dialog(对话框)是Android中常用的UI组件,用于临时显示重要信息或获取用户输入,本文给大家介绍Android中Dialog的使用,感兴趣的朋友一起... 目录android中Dialog的使用详解1. 基本Dialog类型1.1 AlertDialog(

Android Kotlin 高阶函数详解及其在协程中的应用小结

《AndroidKotlin高阶函数详解及其在协程中的应用小结》高阶函数是Kotlin中的一个重要特性,它能够将函数作为一等公民(First-ClassCitizen),使得代码更加简洁、灵活和可... 目录1. 引言2. 什么是高阶函数?3. 高阶函数的基础用法3.1 传递函数作为参数3.2 Lambda

Android自定义Scrollbar的两种实现方式

《Android自定义Scrollbar的两种实现方式》本文介绍两种实现自定义滚动条的方法,分别通过ItemDecoration方案和独立View方案实现滚动条定制化,文章通过代码示例讲解的非常详细,... 目录方案一:ItemDecoration实现(推荐用于RecyclerView)实现原理完整代码实现

Android App安装列表获取方法(实践方案)

《AndroidApp安装列表获取方法(实践方案)》文章介绍了Android11及以上版本获取应用列表的方案调整,包括权限配置、白名单配置和action配置三种方式,并提供了相应的Java和Kotl... 目录前言实现方案         方案概述一、 androidManifest 三种配置方式

Android WebView无法加载H5页面的常见问题和解决方法

《AndroidWebView无法加载H5页面的常见问题和解决方法》AndroidWebView是一种视图组件,使得Android应用能够显示网页内容,它基于Chromium,具备现代浏览器的许多功... 目录1. WebView 简介2. 常见问题3. 网络权限设置4. 启用 JavaScript5. D

Android如何获取当前CPU频率和占用率

《Android如何获取当前CPU频率和占用率》最近在优化App的性能,需要获取当前CPU视频频率和占用率,所以本文小编就来和大家总结一下如何在Android中获取当前CPU频率和占用率吧... 最近在优化 App 的性能,需要获取当前 CPU视频频率和占用率,通过查询资料,大致思路如下:目前没有标准的

Vue项目的甘特图组件之dhtmlx-gantt使用教程和实现效果展示(推荐)

《Vue项目的甘特图组件之dhtmlx-gantt使用教程和实现效果展示(推荐)》文章介绍了如何使用dhtmlx-gantt组件来实现公司的甘特图需求,并提供了一个简单的Vue组件示例,文章还分享了一... 目录一、首先 npm 安装插件二、创建一个vue组件三、业务页面内 引用自定义组件:四、dhtmlx