看到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 stub if(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() { @Override public void onAnimationStart(Animation arg0) { // TODO Auto-generated method stub } @Override public void onAnimationRepeat(Animation arg0) { // TODO Auto-generated method stub } @Override public void onAnimationEnd(Animation arg0) { // TODO Auto-generated method stub if(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.
相关推荐
2D翻转,可以使控件翻转,朋友们可以试试看哦,效果不错
一个实现Android滑屏2D翻转的demo,内容简单可以直接运行,适合新手学习
实现页面批量图片元素翻页效果,有问题联系我 var page1=["img/blue1.png","img/red1.png","img/white1.png"];//第1页 var page2=["img/blue2.png","img/red2.png","img/white2.png"];//第2页 var page3=["img/blue3...
cocoscreator 翻牌效果cocoscreator 翻牌效果cocoscreator 翻牌效果
通过android的简单图片翻转动画,来熟悉android普通动画的使用方法。
html5 canvas左右翻转2d动画
2D效果您可以通过初始化2D JKFlippingView来将2D翻转视图添加到您的应用程序,如下所示。JKFlippingView* flippingView2D = [[JKFlippingView alloc ] init2DFlapWithPosition: JKFlapOpening2DPositionTopLeft and2...
Cocos2D游戏之旅(四):卡牌翻转效果的实现 博客讲解地址:http://blog.csdn.net/qiulanzhu/article/details/47356461
Cocos2D游戏之旅(三):卡牌翻转效果2(只有当鼠标点中卡牌才翻转) 对上一个资源的优化 Cocos2D游戏之旅(三):卡牌翻转效果(屏幕有点击就翻转)
很炫的3D翻转切换图片的效果.自定义View,包含多个效果.百叶窗,3D轮转,3D开合,3D翻转,2d平移
egret项目源码:2d纸牌翻转,达到3d的效果,项目完整源码下载
cocos2d-x3.10 翻页、翻牌效果的实现 http://blog.csdn.net/glunoy
Cocos2D游戏之旅(三):卡牌翻转效果的实现 博客讲解地址:http://blog.csdn.net/qiulanzhu/article/details/47220071
Cocos2D-html5 2.1.4 实现鼠标控制物体旋转 需要Cocos2D-html5 2.1.4源码及XAMPP环境 相应文章链接:http://blog.csdn.net/johnhany/article/details/9298109 Cocos2D-html5 2.1.4源码下载:...
适用于毕业设计参考,具体的CAD图纸、Solidworks三维实体模型在PDF书签的最后一个,打开即可
利用Unity的UGUI制作了2D卡牌翻转的效果,如果是sprite对象的话,原理应该也是一样的,以下是效果图 图1 卡牌翻转效果 关于DoTween DoTween是一款十分强大且好用的动画效果插件,有免费版和收费版,免费版就可以...
没有它,y 轴上的简单翻转会显得非常 2D,并失去其独特的 3D 感觉。 看看,看看它的外观。 AnimationFactory 类中还有许多其他动画。 享受。 如何安装 在此处获取源的副本。 将 /src/com 文件夹复制粘贴到项目的...
cocos2d -iphone 引擎 3.0 版本 的简单 忍者发射飞镖代码,忍者可以飞,翻转,发射飞镖碰撞到 右方 来袭的怪物 飞镖和怪物同时消失,初级项目
cocos creator写的记忆翻牌大师,基本功能都有实现,类似微信小游戏《记忆翻牌大师》。第一张与第二张相同的话两张都会翻到正面,否则都会返回到背面