Android图形动画 使用ScaleAnimation
使用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" ><ImageViewandroid:id="@+id/ivA"android:layout_width="fill_parent"android:layout_height="fill_parent"android:src="@drawable/image_a" /><ImageViewandroid: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); @Overrideprotected void onCreate(Bundle savedInstanceState) {super.onCreate(savedInstanceState);setContentView(R.layout.activity_main);initView();findViewById(R.id.root).setOnClickListener(new OnClickListener() {@Overridepublic 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() {@Overridepublic void onAnimationStart(Animation animation) {// TODO Auto-generated method stub}@Overridepublic void onAnimationRepeat(Animation animation) {// TODO Auto-generated method stub}@Overridepublic 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图形动画
学习View的时候看到的,记录下 Android图形动画 作者 朱才:http://cnblogs.com/zhucai/ 朱才 微博:http://weibo.com/zhucai 2017/8/1 ...
- Android的动画:ScaleAnimation,AlphaAnimation,RotateAnimation,TranslateAnimation,Code,DrawableAnimation
简介 动画有下面两种情况同一个图形通过视图在界面上进行透明度,缩放,旋转,平移的变化(View动画)在界面的同一个位置上不断切换显示不同的图片(Drawable动画)动画的分类View Animati ...
- Android 动画之ScaleAnimation应用详解
本节讲解ScaleAnimation 动画在应用中的实现,有需要的朋友可以参考下 android中提供了4中动画: AlphaAnimation 透明度动画效果 ScaleAnimation 缩放动画 ...
- android 尺寸变化动画,android ScaleAnimation类:尺寸变化动画类
Android JDK为我们提供了4种动画效果,分别是: AlphaAnimation,RotateAnimation, ScaleAnimation, TranslateAnimation.今天我想 ...
- Android补间动画之ScaleAnimation、AlphaAnimation、RotateAnimation、TranslateAnimation、AnimationSet详解
首发:http://blog.csdn.net/harvic880925/article/details/40117115 一.概述 前两篇,我为大家讲述了利用XML来定义动画及插值器,但在代码中,我 ...
- Android 动画之ScaleAnimation应用具体解释
android中提供了4中动画: AlphaAnimation 透明度动画效果 ScaleAnimation 缩放动画效果 TranslateAnimation 位移动画效果 RotateAnimat ...
- android scaleanimation动画,Android 动画之ScaleAnimation应用详解
android中提供了4中动画: AlphaAnimation 透明度动画效果 ScaleAnimation 缩放动画效果 TranslateAnimation 位移动画效果 RotateAnimat ...
- android属性动画作用范围,Android开发之动画效果浅析(一)
程序运行效果图: Android动画主要包含补间动画(Tween)View Animation.帧动画(Frame)Drawable Animation.以及属性动画Property Animatio ...
- Android Animation动画特效
Android应用中各式各样的交互界面能体现一个Android应用独特的设计理念,为应用增色不少.为了要实现这些效果就需要用到Android中关于动画的API,Android中的动画效果主要分为逐帧动 ...
最新文章
- 雷神开机logo更改_雷神911 pro-钛空版开售,陪你过一个不一样的520
- Linux装ntfs后内存不够,Linux_安装Ubuntu后无法使用NTFS硬盘或移动硬盘, 在安装Ubuntu系统后,存在 - phpStudy...
- c await和java_blog/java/test/awaitility.zh.md at master · c-rainstorm/blog · GitHub
- 【Hihocoder - offer编程练习赛86 - C】跳数游戏(STLset或map预处理,dp)
- linux 隐藏显示终端光标
- JAVA黑马刘意学习笔记
- 《处理器虚拟化技术》
- php在线编辑cad,cad形文件编辑器下载
- 计算机bios更改usb端口,联想电脑bios怎么设置usb接口
- php revel,golang,revel_Revel 的路由问题,golang,revel - phpStudy
- java redis哨兵配置_redis哨兵配置主从
- matlab 广义最小二乘,广义最小二乘辨识的matlab实现
- python求次幂_python如何求次幂?
- 基于Spring+SpringMVC+MyBatis博客系统的开发教程(十六)
- html文字自动放大缩小单位,如何css控制字体按百分比放大缩小
- 如何用excel做正交分析_利用Excel进行正交设计及分析.pdf
- Mysql时间函数用法
- Python同步学习(一)
- 微信签到 表单 mysql_java做的一个简易的微信签到系统
- 一位算法工程师对自己工作的反思,写的不错。