animation rotate_canvas scale

animation rotate_canvas scaleScaleAnimation、RotateAnimation、ScaleAnimation、TranslateAnimation详解

大家好,又见面了,我是你们的朋友全栈君。如果您正在找激活码,请点击查看最新教程,关注关注公众号 “全栈程序员社区” 获取激活教程,可能之前旧版本教程已经失效.最新Idea2022.1教程亲测有效,一键激活。

Jetbrains全系列IDE稳定放心使用

animation rotate_canvas scale

点击按钮有相应的效果!

解析在代码注释里!!!

main.xml

<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"
    tools:context="${relativePackage}.${activityClass}" >

    <TextView
        android:id="@+id/text"
        android:background="#FFFF00"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="@string/hello_world"
    
        />

    <Button
        android:id="@+id/translate"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:layout_alignParentBottom="true"
        android:text="测试translate效果" />

    <Button
        android:id="@+id/alpha"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:layout_above="@id/translate"
        android:text="测试alpha效果" />

    <Button
        android:id="@+id/rotate"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:layout_above="@id/alpha"
        android:text="测试rotate效果"
         />
    
     <Button
        android:id="@+id/scale"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:layout_above="@id/rotate"
        android:text="测试scale效果"
         />

      

</RelativeLayout>


main.java

package com.fzq.animation;

import android.app.Activity;
import android.os.Bundle;
import android.view.Menu;
import android.view.MenuItem;
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.TextView;

public class MainActivity extends Activity {
	private Button translate, alpha, rotate, scale;
	private TextView text;

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.activity_main);
		translate = (Button) findViewById(R.id.translate);
		alpha = (Button) findViewById(R.id.alpha);
		rotate = (Button) findViewById(R.id.rotate);
		scale = (Button) findViewById(R.id.scale);
		text = (TextView) findViewById(R.id.text);

		translate.setOnClickListener(new transLateListener());
		alpha.setOnClickListener(new alphaListener());
		rotate.setOnClickListener(new rotateListener());
		scale.setOnClickListener(new scaleListener());
	}

	class transLateListener implements OnClickListener {

		@Override
		public void onClick(View v) {
			// TODO Auto-generated method stub

			AnimationSet animationSet = new AnimationSet(true);
			/*
			 * tanslateAnimation的2种参数方法
			 */

			/*
			 * 第一种 ----> TranslateAnimation(fromXDelta, toXDelta, fromYDelta, toYDelta)
			 * 从坐标(fromXDelta,fromYDelta)移动到(toXDelta,toYDelta),这些坐标都表示增量坐标
			 * 
			 * 解释如下:
			 * 设当前A坐标为(50,50) TranslateAnimation(10,15,20,25),
			 * 那么A点是从起始点(50+10,50+20)【注意!并不是从(50,50)】移动到当前点(50+15,50+25)
			 * 
			 * 效果:
			 * A(50, 50)跳跃到相对于该位置(10,20)的点B【B的坐标为(50+10,50+20)】,在移动到相对于A点(15,25 )的点C【C的坐标为(50+15,50+25)】
			 * 
			 * TranslateAnimation translateAnimation=new
			 * TranslateAnimation(10,15,20,25);
			 */

			/*
			 * 第二种 ---> TranslateAnimation(fromXType, fromXValue, toXType,toXValue, fromYType, fromYValue, toYType, toYValue)移动的坐标还是增量坐标
			 * Type有三种,Value的值一起说明: Animation.ABSOLUTE,
			 * 为绝对位置。value值为50,既为相对于当前位置增量为50的坐标点
			 * Animation.RELATIVE_TO_SELF(相对自己),Animation.RELATIVE_TO_PARENT(相对父控件)。value的值都为百分比(0-1.0) 
			 * 
			 * 解释如下:
			 * new TranslateAnimation( Animation.RELATIVE_TO_SELF, 0.5f,
			 *  Animation.ABSOLUTE, 10, Animation.RELATIVE_TO_SELF, 0.5f,
			 * Animation.ABSOLUTE, 10); 
			 * 设View的宽为100,高为50     就是从(100*0.5,50*0.5)的增量点移动到(10,10)增量点
			 * 
			 * 效果:
			 *假设当前坐标为(50,50),那么A(50,50)跳跃到相对于该位置
			 * (100*0.5,50*0.5)的点B【B的坐标为(50+100*0.5,50+50*0.5)】,
			 * 在移动到相对于A点(10,10)的点C【C的坐标为(50+10,50+10)】
			 */

			TranslateAnimation translateAnimation = new TranslateAnimation(
					Animation.RELATIVE_TO_SELF, 1f, Animation.ABSOLUTE, 400,
					Animation.RELATIVE_TO_SELF, 1f, Animation.ABSOLUTE, 400);

			translateAnimation.setDuration(2000);
			animationSet.addAnimation(translateAnimation);
			text.setAnimation(animationSet);
		}

	}

	class alphaListener implements OnClickListener {

		@Override
		public void onClick(View v) {
			// TODO Auto-generated method stub

			// 创建一个Animatioset对象
			AnimationSet animationSet = new AnimationSet(true);
			// 创建AlphaAnimation对象
			
			/*
			 * 
			  AlphaAnimation(float fromAlpha, float toAlpha)
			  第一个参数fromAlpha为 动画开始时候透明度
			  第二个参数toAlpha为 动画结束时候透明度
			 
			 */
			AlphaAnimation alphaAnimation = new AlphaAnimation(1, 0);
			
			
			// 设置动画执行所需要的时间
			alphaAnimation.setDuration(1000);
			// 将alphaAnimation对象添加到AnimationSet当中
			animationSet.addAnimation(alphaAnimation);
			// 使用控件执行动画效果
			text.setAnimation(animationSet);

		}

	}

	class rotateListener implements OnClickListener {

		@Override
		public void onClick(View v) {
			// TODO Auto-generated method stub
			AnimationSet animationSet = new AnimationSet(true);
			/*
			 * 
			 * fromDegrees    起始时物件的角度  
			 * toDegrees        结束时物件的角度 可以大于360度
			 * 【度数为负数—表示逆时针旋转】
			 * 
			 * pivotX,        动画相对于物件的X坐标的开始位置
			 * pivotY       动画相对于物件的X坐标的开始位置
			 * pivotX pivotY都从0-100%中取值】
			 * 
			    pivotXType:X轴的伸缩模式,可以取值为ABSOLUTE、RELATIVE_TO_SELF、RELATIVE_TO_PARENT。
				pivotXValue:X坐标的伸缩值。
				pivotYType:Y轴的伸缩模式,可以取值为ABSOLUTE、RELATIVE_TO_SELF、RELATIVE_TO_PARENT。
                pivotYValue:Y坐标的伸缩值
			 * 
			 *  new RotateAnimation(0, 360,Animation.RELATIVE_TO_PARENT, 0f,Animation.RELATIVE_TO_PARENT, 0.5f);
			 *  解释如下:
			 *  条件:设图片大小为(100,80),图片左上角的坐标为(0,0);
			 *  效果:以(图片的父控件的宽度*0,图片的父控件的高度*0.5)为原点,图片旋转360度。
			 * 
			 */
			
			RotateAnimation rotateAnimation = new RotateAnimation(0, 360,
					Animation.RELATIVE_TO_PARENT, 0f,
					Animation.RELATIVE_TO_PARENT, 0.5f);
			rotateAnimation.setDuration(1000);
			animationSet.addAnimation(rotateAnimation);
			text.setAnimation(animationSet);
		}

	}

	class scaleListener implements OnClickListener {

		@Override
		public void onClick(View v) {
			// TODO Auto-generated method stub
			AnimationSet animationSet = new AnimationSet(true);

			/*  ScaleAnimation的三种参数方法*/
			/*
			 * fromX:起始X坐标上的伸缩尺寸
			 * toX:结束X坐标上的伸缩尺寸
			 * fromY:起始Y坐标上的伸缩尺寸
			 * toY:结束Y坐标上的伸缩尺寸
			 * 
			 * pivotX表示缩放的中轴点X坐标,距离自身左边缘的位置
			 * pivotY表示缩放的中轴点Y坐标,距离自身上边缘的位置
			 * 
			 * 
			 * pivotXType:X轴的伸缩模式,可以取值为ABSOLUTE、RELATIVE_TO_SELF、RELATIVE_TO_PARENT。
				pivotXValue:X坐标的伸缩值。
				pivotYType:Y轴的伸缩模式,可以取值为ABSOLUTE、RELATIVE_TO_SELF、RELATIVE_TO_PARENT。
                pivotYValue:Y坐标的伸缩值
			
			 第一种 ---> new ScaleAnimation(fromX, toX, fromY, toY);
			 解释如下:
			 ScaleAnimation(0.8f, 0.2f, 0.8f, 0.2f),
			 条件:设图片起始尺寸为(100,80),左上角的坐标为(0,0)
			 效果:以左上角的坐标为准, 从 宽100*0.8,高80*0.8  伸缩到 100*0.2, 高80*0.2
			 
			 第二种 --->new ScaleAnimation(fromX, toX, fromY, toY, pivotX, pivotY)
			 
			 
			 第三种 --->new ScaleAnimation(fromX, toX, fromY, toY, pivotXType, pivotXValue, pivotYType, pivotYValue)
			 解释如下:
			 ScaleAnimation(0.8f, 0.5f, 0.8f,0.5f, Animation.RELATIVE_TO_SELF ,0.5f,Animation.RELATIVE_TO_SELF, 0.5f);
			 条件:设图片的尺寸为(100,80),左上角的坐标为(0,0),那么中心点的坐标为(50,40)
			 效果:以中心点(50,40)为准, 图片从宽100*0.8f,高80*0.8 伸缩到 100*0.5, 高80*0.5

			*/
			
			ScaleAnimation scaleAnimation = new ScaleAnimation(0.8f, 0.5f, 0.8f,0.5f, Animation.RELATIVE_TO_SELF ,0.5f,
					Animation.RELATIVE_TO_SELF, 0.5f);
					

			scaleAnimation.setDuration(1000);
			animationSet.addAnimation(scaleAnimation);
			text.setAnimation(animationSet);

		}
	}
}


版权声明:本文内容由互联网用户自发贡献,该文观点仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请联系我们举报,一经查实,本站将立刻删除。

发布者:全栈程序员-站长,转载请注明出处:https://javaforall.net/181804.html原文链接:https://javaforall.net

(0)
全栈程序员-站长的头像全栈程序员-站长


相关推荐

  • 上位机plc编程入门_【新手入门】西门子PLC编程入门学习

    上位机plc编程入门_【新手入门】西门子PLC编程入门学习一、S7-200PLC的硬件结构及系统构成、安装与接线学习1、学习什么内容?重点学习什么内容?(1)PLC的硬件结构(2)PLC的系统构成及CPU和模块参数(3)PLC的选型,安装及接线(重点)2、如何进行学习(学练结合)(1)学习S7-200从入门到精通的第一章内容(2)PLC是技术是一门实践性很强的技术,所有需要用于一台PLC,熟悉PLC的硬件结构,练习PLC与外围设备的接线链接。建议使用技…

    2022年9月7日
    1
  • GoogleMaps_键盘网站

    GoogleMaps_键盘网站在Google地球中使用键盘/鼠标导航首先要明白导航过程中的三个中心,视野中心,相机视角,鼠标锁定位置。还要明白3D视图和俯视图、地平面视图的区别,因为在海拔为0时将进入地平面视图,上下的操作将变为拉近和推远。中间的位置为视野中心,可以通过Ctrl+Shif+左箭头/右箭头来触发显示,如果要展示的对象不在视野中心,可以通过Alt+左箭头/右箭头进行对象位置微调。-/+的中心为视野中心。相机视角可以通过Ctrl触发,为可以通过左箭头/右箭头控制水平方向旋转,上箭头/下箭头控制上下方向旋

    2022年9月2日
    5
  • GD32 RT-Thread Nano+FinSH组件

    GD32 RT-Thread Nano+FinSH组件一、FinSH组件的命令执行流程图二、执行环境1.芯片:GD32F10x2.串口: #defineFINSH_UART USART1 #defineFINSH_UART_CLK RCU_USART1 #defineFINSH_TX_PIN GPIO_PIN_2 …

    2022年5月21日
    88
  • CTF逆向-Upx脱壳攻防世界simple unpack

    CTF逆向-Upx脱壳攻防世界simple unpack文章目录前言UPX技术原理应用范围软件使用CTF实战程序查壳UPX脱壳总结前言加壳软件分两类:压缩壳:压缩的目的是减少程序体积,如ASPack、UPX、PECompact等;加密壳:加密是为了防止程序被反编译(反汇编)、跟踪和调试,如ASProtect、Armadillo、EXECryptor、Themida、VMProtect。壳的存在会让我们找不到程序的真实入口点,从而不能正确的分析反汇编程序,也就对程序起到了一定的保护作用。加密壳的基本思路:将原本程序的PE相关代码复制

    2022年7月19日
    38
  • rabbitmqkafka对比_全场景

    rabbitmqkafka对比_全场景这是陈东景于2021年8月29日下午16点原创作品,转载请标明出处!!!!在进行软件设计的过程中,如果软件设计业务上存在需要短时间内处理大批量的信息,又需要能保证软件能正常运行(保证软件的高可靠和高可用)。因为大批量(几十万,几百万级别的数据或者消息需要同一个时间处理),软件的IO过高,会导致软件运行阻塞或者消耗内存过高而崩溃,甚至是宕机。消息队列的概念被提了出来,通过缓存消息的模式,进行生产和消费。通过异步处理的方式,解耦这种短时间内出现大批量需要处理消息的场景。目前我们使用到的比…

    2022年10月14日
    2
  • docker命令大全

    docker命令大全1、启动dockersystemctlstartdocker2、

    2022年5月16日
    44

发表回复

您的邮箱地址不会被公开。 必填项已用 * 标注

关注全栈程序员社区公众号