当前位置:操作系统 > 安卓/Android >>

Android 技术总结(001)—— Tab页面手势滑动切换以及动画效果

效果图。

  

3张页卡之间的切换。带动画效果。

工程结构。


主要应用到android-support-v4.jar这个jar包。
布局文件。
1、main.xml中的代码

[html]
<?xml version="1.0" encoding="utf-8"?> 
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    xmlns:umadsdk="http://schemas.android.com/apk/res/com.LoveBus" 
    android:layout_width="fill_parent" 
    android:layout_height="fill_parent" 
    android:orientation="vertical" > 
 
    <LinearLayout 
        android:id="@+id/linearLayout1" 
        android:layout_width="fill_parent" 
        android:layout_height="100.0dip" 
        android:background="#FFFFFF" > 
 
        <TextView 
            android:id="@+id/text1" 
            android:layout_width="fill_parent" 
            android:layout_height="fill_parent" 
            android:layout_weight="1.0" 
            android:gravity="center" 
            android:text="页卡1" 
            android:textColor="#000000" 
            android:textSize="22.0dip" /> 
 
        <TextView 
            android:id="@+id/text2" 
            android:layout_width="fill_parent" 
            android:layout_height="fill_parent" 
            android:layout_weight="1.0" 
            android:gravity="center" 
            android:text="页卡2" 
            android:textColor="#000000" 
            android:textSize="22.0dip" /> 
 
        <TextView 
            android:id="@+id/text3" 
            android:layout_width="fill_parent" 
            android:layout_height="fill_parent" 
            android:layout_weight="1.0" 
            android:gravity="center" 
            android:text="页卡3" 
            android:textColor="#000000" 
            android:textSize="22.0dip" /> 
    </LinearLayout> 
 
    <ImageView 
        android:id="@+id/cursor" 
        android:layout_width="fill_parent" 
        android:layout_height="wrap_content" 
        android:scaleType="matrix" 
        android:src="@drawable/a" /> 
 
    <android.support.v4.view.ViewPager 
        android:id="@+id/vPager" 
        android:layout_width="wrap_content" 
        android:layout_height="wrap_content" 
        android:layout_gravity="center" 
        android:layout_weight="1.0" 
        android:background="#000000" 
        android:flipInterval="30" 
        android:persistentDrawingCache="animation" /> 
 
</LinearLayout> 
2、lay1.xml
[html] 
<?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:background="#158684" 
    android:orientation="vertical" > 
 
</LinearLayout> 
3、lay2.xml
[html]
<?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:background="#FF8684" 
    android:orientation="vertical" > 
 
</LinearLayout> 
4、lay3.xml
[html] 
<?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:background="#1586FF" 
    android:orientation="vertical" > 
 
</LinearLayout> 

主要代码。
[java] 
/**
 * Tab页面手势滑动切换以及动画效果
 * 
 */ 
public class MainActivity extends Activity { 
    // ViewPager是google SDk中自带的一个附加包的一个类,可以用来实现屏幕间的切换。 
    // android-support-v4.jar 
 

补充:移动开发 , Android ,
CopyRight © 2012 站长网 编程知识问答 www.zzzyk.com All Rights Reserved
部份技术文章来自网络,