看到android实现的一个效果视频,就学习一下:

一、2D翻转:

呵,我来说就是一张图片先收缩,另一张图片在展开.

二、实现效果:



三、实现源码:

Main:

package com.example.card2d;import android.os.Bundle;import android.app.Activity;import android.view.Menu;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;import android.widget.Toast;public class MainActivity extends Activity {private ImageView imgeA;private ImageView imgeB;//创建动画private ScaleAnimation sato1 =new ScaleAnimation(1, 0, 1, 1, Animation.RELATIVE_TO_PARENT, 0.5f, Animation.RELATIVE_TO_PARENT, 0.5f);private ScaleAnimation sato2 =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() {public void onClick(View arg0) {// TODO Auto-generated method stubif(imgeA.getVisibility() == View.VISIBLE){imgeA.startAnimation(sato1);}else{imgeB.startAnimation(sato1);}}});    }    private void showImgA(){        imgeA.setVisibility(View.VISIBLE);    imgeB.setVisibility(View.INVISIBLE);        }     private void showImgB(){        imgeA.setVisibility(View.INVISIBLE);    imgeB.setVisibility(View.VISIBLE);        }              private void initView(){    imgeA =(ImageView) findViewById(R.id.viA);    imgeB =(ImageView) findViewById(R.id.viB);    showImgA();    sato1.setDuration(500);    sato2.setDuration(500);        sato1.setAnimationListener(new AnimationListener() {@Overridepublic void onAnimationStart(Animation arg0) {// TODO Auto-generated method stub}@Overridepublic void onAnimationRepeat(Animation arg0) {// TODO Auto-generated method stub}@Overridepublic void onAnimationEnd(Animation arg0) {// TODO Auto-generated method stubif(imgeA.getVisibility() == View.VISIBLE){imgeA.setAnimation(null);showImgB();imgeB.startAnimation(sato2);}else{imgeB.setAnimation(null);showImgA();imgeA.startAnimation(sato2);}}});   }    }

布局文件:

<FrameLayout 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:id="@+id/root"    tools:context=".MainActivity" >    <ImageView         android:layout_width="match_parent"        android:layout_height="match_parent"        android:id="@+id/viA"        android:src="@drawable/c1"        />    <ImageView         android:layout_width="match_parent"        android:layout_height="match_parent"        android:id="@+id/viB"        android:src="@drawable/c2"        /></FrameLayout>

四、分析:

源码很简单,看看就懂了.

执行过程:

当鼠标点击的时候,imgeA执行动画1,imgeA进行收缩,当动画1结束时,执行showImgB(),使得imgeA隐藏,imgeB显示,而imgeB的显示效果,就要imgeB执行动画2.

当鼠标第二次点击的时候,imgeB执行动画1,进行图片收缩,当动画结束时,执行showImgA(),使得imgeA显示,imgeB隐藏,imgeA的显示效果,就要imgeA执行动画2.

更多相关文章

  1. Android拍照,照片会自己旋转
  2. (4.2.0)GitHub开源项目收集
  3. Android:popupwindow实现底部弹窗实例
  4. 把这份关于Android(安卓)Binder原理一系列笔记研究完,进大厂是个
  5. android手势实现图片的拖动和缩放效果
  6. Flutter事件分发源码剖析
  7. Android应用程序进程启动源码解析
  8. Android(安卓)UI组件框架AndroidMaterialDesign详解
  9. [Android开发实战]Android手势密码(支付宝手势密码)实现(支持2.x)

随机推荐

  1. flex基础:flex项目上的三个属性以及利用fl
  2. 用 GPT-2 自动写诗,从五言绝句开始
  3. 数学之美中盛赞的 Michael Collins 教授,
  4. 敖丙离职了
  5. .net 加密模型的学习笔记
  6. VS2017使用QCustomPlot第三方库存在的问
  7. 神器! 统计和金融计算器, 词云和情感分析
  8. 中国博导要求掌握的RDD方法实证运用范文(
  9. 2020秋招总结:凡是过往,皆为序章
  10. 【Github】NLPer-Interview: NLP 算法工