使用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中提供了4中动画: AlphaAnimation 透明度动画效果 ScaleAnimation 缩放动画效果 TranslateAnimation 位移动画效果 RotateAnimation 旋转动画效果 本节讲解ScaleAnimation 动画, ScaleAnimation(float fromX...
android Tween ScaleAnimation TranlateAnimation
Android各种动画效果ScaleAnimation,AlphaAnimation,TranslateAnimation,RotateAnimation(文章结尾有代码)
android scaleanimation 代码~~~~~~~~~~~~~~~~~~~~~~
Android Java动画使用Java的Android动画规模建设者ScaleAnimation(Context context,AttributeSet attrs)从资源加载ScaleAnimation时使用的构造方法。 ScaleAnimation(float fromX,float toX,float fromY,...
android动画 AlphaAnimation(透明度动画效果 );RotateAnimation(旋转动画效果);ScaleAnimation(缩放动画效果 ); TranslateAnimation(位移动画效果 )
包含AlphaAnimation渐变效果 TranslateAnimation:位移渐变... ScaleAnimation:缩放渐变 RotateAnimation:旋转渐变 AnimationSet:组合渐变 frameAnimation:帧动画的xml和代码实现方式,非常适合新手朋友参考。
AlphaAnimation 渐变透明度动画效果 ScaleAnimation 渐变尺寸伸缩动画效果 TranslateAnimation 画面转换位置移动动画效果 RotateAnimation 画面转移旋转动画效果
缩放Scale动画(ScaleAnimation),支持多值,,支持设置轴点 4.全屏滑动Slide动画(SlideAnimation),支持上下左右四个方向移入与移出 5.自身控件范围内滑动动画(SlideUnderneathAnimation),支持上下左右四个...
android动画基础 XML中 alpha 渐变透明度动画效果 scale 渐变尺寸伸缩动画效果 translate 画面转换位置移动动画效果 rotate 画面转移旋转动画效果 JavaCode中 AlphaAnimation 渐变透明度动画效果 ScaleAnimation ...
缩放动画标签,使用的子类名称为ScaleAnimation,实现的效果是整个View的放大或者缩小。 旋转动画标签使用的子类名称是RotateAnimation,实现的效果是将整个View进行旋转。 透明度动画标签使用的子类名称是...
在Andriod开发中,Animation是用来给控件... 根据我们需要的动态效果创建一个Animation类,主要有4个这样的类,分别为AlphaAnimation,ScaleAnimation,RotateAnimation,TranslateAnimation,分别对应着一种动画效果。
本文目录补间动画概述和分类各类补间动画实现xml实现补间动画透明度动画-AlphaAnimation缩放动画-ScaleAnimation位移动画-TranslateAnimation旋转动画-RotateAnimation动画组合-AnimationSet代码实现补间动画透明度...
之前说过了在Android中,动画Animation的实现有两种方式:Tween Animation(渐变动画)和Frame Animation(帧动画)。渐变动画是通过对场景里的对象不断做图像变换(平移、缩放、旋转等)产生动画效果。帧动画则是...
动画类型 Android的animation由四种类型组成 XML中 alpha 渐变透明度动画效果 ...渐变尺寸伸缩动画效果 ...画面转换位置移动动画效果 ...Android动画模式 Animation主要有两种动画模式: 一种是tweened
android 下拉,淡入淡出特效源码 依赖support v7 // /** * PopupWindow上菜单进入动画 */ public static Animation createPopupAnimIn(Context context, int fromYDelta) { AnimationSet animationSet = new ...
1.2.android实现动画方式: 编码方式 xml方式 1.3. 动画Api : scaleAnimation1.setStartOffset(1000); // 动画延迟时间 scaleAnimation1.setDuration(10000); // 持续时间 scaleAnimation
Android 平台提供了两类动画。 一类是Tween动画,就是对场景里的对象不断的进行图像变化来产生动画效果(旋转、平移、放缩和渐变)。 下面就讲一下Tweene Animations。 主要类: Animation 动画 AlphaAnimation 渐变...
补间动画 AlphaAnimation TranslateAnimation ScaleAnimation RotateAnimation