Android图形动画 使用ScaleAnimation

Android图形动画 使用ScaleAnimation使用ScaleAnimation实现了一个类似于翻转的动画效果。感觉ScaleAnimation算是一个比较好用的动画类了,看了一下API感觉方法和构造方法也都很简单。就不再赘述太多直接上代码吧– 第一步:准备两张照片,放置在res/drawble下。首先在layout中写好布局文件,这里要用framelayout布局,让两张图片一张覆盖在另一张上。相信聪明的你…

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

Jetbrains全系列IDE使用 1年只要46元 售后保障 童叟无欺

使用ScaleAnimation实现了一个类似于翻转的动画效果。

感觉ScaleAnimation算是一个比较好用的动画类了,看了一下API感觉方法和构造方法也都很简单。

就不再赘述太多直接上代码吧- –

 

第一步:

准备两张照片,放置在res/drawble下。

首先在layout中写好布局文件,这里要用framelayout布局,让两张图片一张覆盖在另一张上。

相信聪明的你看到这里已经秒懂等下的图片处理方式了。

<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:id="@+id/root"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    tools:context="com.example.dfanzhuan.MainActivity" >

    <ImageView
        android:id="@+id/ivA"
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"
        android:src="@drawable/image_a" />

    <ImageView
        android:id="@+id/ivB"
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"
        android:src="@drawable/image_b" />

</FrameLayout>

 第二部:

MainActivity.java

import android.app.Activity;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.animation.Animation;
import android.view.animation.Animation.AnimationListener;
import android.view.animation.ScaleAnimation;
import android.widget.ImageView;

public class MainActivity extends Activity {

	private ImageView imgA;
	private ImageView imgB;
	
	private ScaleAnimation sato0 = new ScaleAnimation(1, 0, 1, 1, 
			Animation.RELATIVE_TO_PARENT, 0.5f, Animation.RELATIVE_TO_PARENT, 0.5f);           
	private ScaleAnimation sato1 = new ScaleAnimation(0, 1, 1, 1, 
			Animation.RELATIVE_TO_PARENT, 0.5f, Animation.RELATIVE_TO_PARENT, 0.5f);           
	
	
	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.activity_main);
		initView();
		findViewById(R.id.root).setOnClickListener(new OnClickListener() {
			
			@Override
			public void onClick(View v) {
				if (imgA.getVisibility() == View.VISIBLE) {
					imgA.startAnimation(sato0);
				}else {
					imgB.startAnimation(sato0);
				}
			}
		});
	}
	
	private void showImageA() {
		imgA.setVisibility(View.VISIBLE);
		imgB.setVisibility(View.INVISIBLE);
	}
	
	private void showImageB() {
		imgA.setVisibility(View.INVISIBLE);
		imgB.setVisibility(View.VISIBLE);
	}
	
	private void initView() {
		//指定执行时间
		imgA = (ImageView) findViewById(R.id.ivA);
		imgB = (ImageView) findViewById(R.id.ivB);
		showImageA();
		//动画执行时间
		sato0.setDuration(500);
		sato1.setDuration(500);
		
		sato0.setAnimationListener(new AnimationListener() {
			
			@Override
			public void onAnimationStart(Animation animation) {
				// TODO Auto-generated method stub
				
			}
			
			@Override
			public void onAnimationRepeat(Animation animation) {
				// TODO Auto-generated method stub
				
			}
			
			@Override
			public void onAnimationEnd(Animation animation) {
				if (imgA.getVisibility() == View.VISIBLE) {
					imgA.setAnimation(null);
					showImageB();
					imgB.startAnimation(sato1);
				} else {
					imgB.setAnimation(null);
					showImageA();
					imgA.startAnimation(sato1);
					
				}
			}
		});
	}

}

 个人感觉难点在于对时间和图片翻转情况的理解,不过写几次以后就just soso了~

下面是效果图,因为还不会做git。。。所以发四张好了:

Android图形动画 使用ScaleAnimation
 
Android图形动画 使用ScaleAnimation
 

Android图形动画 使用ScaleAnimation
 
Android图形动画 使用ScaleAnimation
 

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

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

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


相关推荐

  • 关于Js后退几种方式

    关于Js后退几种方式2019独角兽企业重金招聘Python工程师标准>>>…

    2022年7月25日
    9
  • 触摸事件中touchstart、touchmove、touchend、touchcancel事件应用方法及实例

    触摸事件中touchstart、touchmove、touchend、touchcancel事件应用方法及实例触摸事件中touchstar、touchmove、touchend、touchcancel事件应用方法及实例一、分享到:前面我们介绍过移动设备中一些设备事件,例如手机旋转90度、倾斜等设置放置姿态变化的四大事件orientationchange事件、MozOrientation事件、deviceorientation事件、devicemotion事件,接下由南昌网站…

    2022年6月19日
    30
  • c51单片机流水灯程序汇编语言,基于51单片机的流水灯程序

    c51单片机流水灯程序汇编语言,基于51单片机的流水灯程序LED流水灯的开发在51单片机中再常见不过了,主要是让大家掌握IO的操作是单片机控制最基本的要求。根据开发流程,我们先查看选型的单片机的资源和控制寄存器,然后在软件上实现控制。在这里芯片我们采用STC15W404AS作为开发的硬件平台,在这里我们用该单片机的P1引脚来驱动LED实现流水灯的功能。如图是LED连接的硬件电路,可以看到8颗LED是阳极通过限流电阻共同连接到VCC上的,也就是说当LED…

    2022年5月7日
    77
  • 【C语言】输入一组整数,求出这组数字子序列和中最大值

    【C语言】输入一组整数,求出这组数字子序列和中最大值

    2022年1月30日
    50
  • 研华acdp手机版_acwing算法基础

    研华acdp手机版_acwing算法基础你准备游览一个公园,该公园由 N 个岛屿组成,当地管理部门从每个岛屿出发向另外一个岛屿建了一座桥,不过桥是可以双向行走的。同时,每对岛屿之间都有一艘专用的往来两岛之间的渡船。相对于乘船而言,你更喜欢步行。你希望所经过的桥的总长度尽可能的长,但受到以下的限制:可以自行挑选一个岛开始游览。任何一个岛都不能游览一次以上。无论任何时间你都可以由你现在所在的岛 S 去另一个你从未到过的岛 D。由 S 到 D 可以有以下方法:(1)步行:仅当两个岛之间有一座桥时才有可能。对于这种情况,桥的长度会累加到你步

    2022年8月9日
    8
  • curd php,laravel通用化的CURD的实现

    curd php,laravel通用化的CURD的实现说明非常高效的处理laravel中curd的操作安装composerrequireshencongcong/laravel-curd~1.0laravel项目的config/app.php注册ServiceProvider’providers’=>[//…Shencongcong\LaravelCurd\LaravelCurdServiceProvider::class…

    2025年6月16日
    4

发表回复

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

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