Github项目地址:https://github.com/openaphid/android-flip
效果图一:
效果图二:
先看一下,使用是多么简单,首先有两个布局。
布局一:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical"
android:background="@android:color/white"
>
<TextView android:layout_width="fill_parent" android:layout_height="wrap_content"
android:textSize="24dip"
android:text="@string/first_page_title"
android:background="@android:color/white"
android:textColor="@android:color/black" android:textStyle="bold"/>
<TextView android:layout_width="fill_parent" android:layout_height="wrap_content"
android:layout_weight="1.0"
android:layout_marginTop="8dp"
android:textSize="16dp"
android:background="@android:color/white"
android:textColor="@android:color/black"
android:text="@string/first_page_description"
/>
<ImageView android:layout_width="fill_parent" android:layout_height="wrap_content"
android:background="@android:color/white"
android:src="@drawable/aphid_logo"
/>
</LinearLayout>
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical"
android:background="@android:color/white"
>
<TextView android:layout_width="fill_parent" android:layout_height="wrap_content"
android:textSize="24dip"
android:text="@string/second_page_title"
android:background="@android:color/white"
android:textColor="@android:color/black"
android:shadowColor="@android:color/background_light"
android:shadowDx="2"
android:shadowRadius="5"
android:textStyle="bold"/>
<TextView android:layout_width="fill_parent" android:layout_height="wrap_content"
android:layout_weight="1.0"
android:layout_marginTop="8dp"
android:textSize="16dp"
android:background="@android:color/white"
android:textColor="@android:color/black"
android:text="@string/second_page_description"
/>
<ImageView android:layout_width="fill_parent" android:layout_height="wrap_content"
android:background="@android:color/white"
android:src="@drawable/aphid_kid"
/>
</LinearLayout>
然后看在MainActivity里面是如何使用的
<span style="font-family: Arial, Helvetica, sans-serif;">private FlipViewGroup contentView;//声明ViewGroup</span>
/**
* Called when the activity is first created.
*/
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setTitle(R.string.activity_title);
contentView = new FlipViewGroup(this);//初始化ViewGroup
//将布局添加到ViewGroup中
contentView.addFlipView(View.inflate(this, R.layout.second_page, null));
contentView.addFlipView(View.inflate(this, R.layout.first_page, null));
setContentView(contentView);
contentView.startFlipping(); //make the first_page view flipping
}