先来看看效果:
[img]http://dl2.iteye.com/upload/attachment/0094/6152/35ad98ce-42ee-3c85-aee4-74642f902e68.png[/img]
简单介绍一下,两个界面,以水平中线旋转180度,切换界面。
上代码:
布局文件:
Activity关键代码:
代码中还有两个动画类,项目代码已分享到github:
[url]https://github.com/kk-java/MyViewFlipper[/url]
[img]http://dl2.iteye.com/upload/attachment/0094/6152/35ad98ce-42ee-3c85-aee4-74642f902e68.png[/img]
简单介绍一下,两个界面,以水平中线旋转180度,切换界面。
上代码:
布局文件:
<RelativeLayout 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"
tools:context=".MainActivity"
android:background="#a8a8a8">
<ViewFlipper
android:id="@+id/viewFlipper"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
>
<include
android:id="@+id/one_layout1"
layout="@layout/activity_one" />
<include
android:id="@+id/two_layout2"
layout="@layout/activity_two"
android:visibility="gone" />
</ViewFlipper>
</RelativeLayout>
Activity关键代码:
private void changeOneOrTwo()
{
float halfWidth = viewFlipper.getWidth() / 2.0f;
float halfHeight = viewFlipper.getHeight() / 2.0f;
int duration = 300;
int depthz = 0;// viewFlipper.getWidth()/2;
if (oneOrTwo == 1)
{
oneOrTwo = 2;
Rotate3dAnimation in = new Rotate3dAnimation(-90, 0, halfWidth,
halfHeight, depthz, false);
in.setDuration(duration);
in.setStartOffset(duration);
viewFlipper.setInAnimation(in);
Rotate3dAnimation out = new Rotate3dAnimation(0, 90, halfWidth,
halfHeight, depthz, false);
out.setDuration(duration);
viewFlipper.setOutAnimation(out);
viewFlipper.showNext();
} else
{
oneOrTwo = 1;
one_layout1.setVisibility(View.VISIBLE);
two_layout2.setVisibility(View.GONE);
Rotate3dAnimation in = new Rotate3dAnimation(90, 0, halfWidth,
halfHeight, depthz, false);
in.setDuration(duration);
in.setStartOffset(duration);
viewFlipper.setInAnimation(in);
Rotate3dAnimation out = new Rotate3dAnimation(0, -90, halfWidth,
halfHeight, depthz, false);
out.setDuration(duration);
viewFlipper.setOutAnimation(out);
viewFlipper.showPrevious();
}
}
代码中还有两个动画类,项目代码已分享到github:
[url]https://github.com/kk-java/MyViewFlipper[/url]