设为首页 加入收藏

TOP

Android 轮换页面+TabHost 实例(一)
2017-10-12 18:05:20 】 浏览:7835
Tags:Android 轮换 页面 TabHost 实例

最终效果展示:

 

首先我们需要一个ViewPager控件,不过可以发现在左侧的控件列表中并没有这个控件

 

这时我们要去升级包中查看

 

 

 

然后在厘米找到 ViewPager.class 这时我们双击这个发现不能查看源代码

 

我们可以通过以 android-support-v4.jar.properties 的一个文件 将其复制到libs目录下 然后双击打开 

 

出现以下代码:

src = E:\\adt-bundle-windows-x86_64-20140702\\sdk\\sources

 

将路径改为你SDK下对应的sources目录即可 注意 \ 符号要用转义字符 \\ 表示!

 

做完以上工作后关闭掉项目重新载入一下即可打开升级包的源代码啦!

 

android-support-v4.jar.properties下载地址:

http://files.cnblogs.com/files/Laopengblog/%E6%9F%A5%E7%9C%8Bsupport.v4%E6%BA%90%E4%BB%A3%E7%A0%81.rar

 

下面我们打开 ViewPager.class  复制一下包名 android.support.v4.view 用其当做控件名称

 

附上完整的主布局代码

<LinearLayout 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:orientation="vertical"
    android:paddingBottom="@dimen/activity_vertical_margin"
    android:paddingLeft="@dimen/activity_horizontal_margin"
    android:paddingRight="@dimen/activity_horizontal_margin"
    android:paddingTop="@dimen/activity_vertical_margin"
    tools:context="com.huarui.my12android2502.MainActivity" >

    <TabHost
        android:id="@android:id/tabhost"
        android:layout_width="match_parent"
        android:layout_height="wrap_content" >

        <LinearLayout
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:orientation="vertical" >

            <TabWidget
                android:id="@android:id/tabs"
                android:layout_width="match_parent"
                android:layout_height="wrap_content" >
            </TabWidget>

            <FrameLayout
                android:id="@android:id/tabcontent"
                android:layout_width="match_parent"
                android:layout_height="match_parent" >
                <!-- 其实没用就是为了占一个空格 -->
                <LinearLayout
                    android:id="@+id/tab1"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content" 
                    android:orientation="vertical">
                </LinearLayout>
            </FrameLayout>
        </LinearLayout>
    </TabHost>

    <android.support.v4.view.ViewPager
        android:id="@+id/vp"
        android:layout_width="fill_parent"
        android:layout_height="match_parent" >
    </android.support.v4.view.ViewPager>

</LinearLayout>
activity_main.xml

我们在创建3个布局用来进行他们之间的切换(随意创建即可,我只放了一个Butten稍微区分一下,代码就省略了)

activity_view1.xml 

activity_view2.xml

activity_view3.xml

 

然后开始主代码的编写 重要的注释都在代码里了

package com.huarui.my12android2502;

import java.util.ArrayList;
import java.util.List;

import android.app.Activity;
import android.app.TabActivity;
import android.os.Bundle;
import android.support.v4.view.PagerAdapter;
import android.support.v4.view.ViewPager;
import android.support.v4.view.ViewPager.OnPageChangeListener;
import android.view.Menu;
import android.
首页 上一页 1 2 3 下一页 尾页 1/3/3
】【打印繁体】【投稿】【收藏】 【推荐】【举报】【评论】 【关闭】 【返回顶部
上一篇Android GZIP压缩IO流,优化APP数.. 下一篇android apk静默安装

最新文章

热门文章

Hot 文章

Python

C 语言

C++基础

大数据基础

linux编程基础

C/C++面试题目