基于Android实现3D翻页效果

2019-12-10 17:55:14于丽
这篇文章主要为大家详细介绍了基于Android实现3D翻页效果的具体代码,具有一定的参考价值,感兴趣的小伙伴们可以参考一下  

最近做了一个简单的3D效果翻页特效,先说说我的思路吧,首先我这个翻页效果并不是两个Activity之间的跳转,而是在同一个activity类切换不同的view而已。我现在的做法是单击一个button然后Gone当前的布局,然后把需要呈现的布局visible,在隐藏当前布局的时候启动动画,然后给动画添加监听,在动画结束时开始另外一个view的入场动画就行了。
下面来看下我的主页面的布局文件:

<FrameLayout xmlns:android="http://www.easck.com/apk/res/android" 
 android:id="@+id/container" 
 android:layout_width="fill_parent" 
 android:layout_height="fill_parent" > 
 
 <include 
 android:layout_width="fill_parent" 
 android:layout_height="fill_parent" 
 layout="@layout/layout2" /> 
 
 <include 
 android:layout_width="fill_parent" 
 android:layout_height="fill_parent" 
 layout="@layout/layout1" /> 
 
</FrameLayout> 

我这个布局文件使用<include>标签包含了另外2个布局文件,这些布局文件才是呈现数据的,下面是另外2个布局文件:

layout1:

<?xml version="1.0" encoding="utf-8"?> 
<LinearLayout xmlns:android="http://www.easck.com/apk/res/android" 
 android:layout_width="match_parent" 
 android:layout_height="match_parent" 
 android:background="@drawable/test1" 
 android:orientation="vertical" 
 android:id="@+id/container1" 
 > 
 
 <Button 
 android:id="@+id/bt_towhile" 
 android:layout_width="wrap_content" 
 android:layout_height="wrap_content" 
 android:layout_gravity="center" 
 android:text="白色" /> 
 
</LinearLayout> 

layout2: