在本示例中,我参考了几个demo整理出来的viewpager的最基本用法,制作了一个类似新闻导航功能的界面,每个页面的下方有对应的项目符号,当页面进行切换的时候项目符号也随之变化,下面是实现后的图片:
java代码:
主页面的布局:
android:layout_width=
"fill_parent"
android:layout_height=
"fill_parent"
android:orientation=
"vertical"
>
android:id=
"@+id/linearLayout1"
android:layout_width=
"fill_parent"
android:layout_height=
"wrap_content"
android:orientation=
"vertical"
>
android:id=
"@+id/guidePages"
android:layout_width=
"fill_parent"
android:layout_height=
"wrap_content"
/>
android:id=
"@+id/linearLayout2"
android:layout_width=
"fill_parent"
android:layout_height=
"wrap_content"
android:orientation=
"vertical"
>
android:layout_width=
"fill_parent"
android:layout_height=
"wrap_content"
android:orientation=
"vertical"
>
android:id=
"@+id/viewGroup"
android:layout_width=
"fill_parent"
android:layout_height=
"wrap_content"
android:layout_alignParentBottom=
"true"
android:layout_marginBottom=
"40dp"
android:gravity=
"center_horizontal"
android:orientation=
"horizontal"
>
|
标题栏的布局:
android:layout_width=
"match_parent"
android:layout_height=
"wrap_content"
android:orientation=
"horizontal"
android:background=
"@drawable/title"
android:gravity=
"center_vertical"
>
android:id=
"@+id/btn_left"
android:layout_width=
"80dp"
android:layout_height=
"30dp"
android:text=
"返回"
android:textSize=
"15sp"
android:textColor=
"@android:color/white"
android:background=
"@drawable/header_btn"
android:layout_margin=
"5dp"
/>
android:id=
"@+id/tvTitle"
android:layout_width=
"wrap_content"
android:layout_height=
"wrap_content"
android:text=
"奥运快报"
android:textSize=
"18sp"
android:layout_weight=
"1"
android:ellipsize=
"end"
android:gravity=
"center_horizontal"
/>
android:id=
"@+id/btn_right"
android:layout_width=
"80dp"
android:layout_height=
"30dp"
android:text=
"首页"
android:textSize=
"15sp"
android:textColor=
"@android:color/white"
android:background=
"@drawable/header_btn"
android:layout_margin=
"5dp"
/>
|
子页面的布局:
android:layout_width=
"match_parent"
android:layout_height=
"match_parent"
android:orientation=
"vertical"
android:background=
"@android:color/white"
>
android:layout_width=
"fill_parent"
android:layout_height=
"wrap_content"
>
android:layout_width=
"fill_parent"
android:layout_height=
"wrap_content"
android:src=
"@drawable/pic_lindan"
/>
android:layout_width=
"fill_parent"
android:layout_height=
"wrap_content"
android:layout_marginTop=
"10dp"
android:layout_marginBottom=
"10dp"
android:layout_marginLeft=
"30dp"
android:layout_marginRight=
"30dp"
android:background=
"@drawable/divider_horizontal_line"
>
android:layout_width=
"fill_parent"
android:layout_height=
"fill_parent"
>
android:layout_width=
"fill_parent"
android:layout_height=
"wrap_content"
android:layout_marginRight=
"30dp"
android:layout_marginLeft=
"30dp"
android:textColor=
"@android:color/black"
android:text=
"@string/string_lindan"
/>
|
其余子页面的布局类。