最近在完成一个新闻客户端项目时,需要做出一个横向标题栏的UI界面,在网上查阅多时,感觉不是很懂,最后自己摸索出来了一种更容易理解,且更加容易的实现方法,废话不多说上图:
首先布局文件
activity_main.xml是主UI的布置,one_layout 到ten_layout是10个按下标题信息所对应的界面,activity_main代码如下:
<span style="font-size:18px;"><span style="font-size:18px;"><?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >
<HorizontalScrollView
android:id="@+id/horizontal"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="30dip"
android:layout_gravity="center_vertical"
>
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:id="@+id/showtitle"
android:layout_gravity="center_vertical"
>
</LinearLayout>
</HorizontalScrollView>
<android.support.v4.view.ViewPager
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:id="@+id/showtitle_content"
>
</android.support.v4.view.ViewPager>
</LinearLayout></span></span>
如上图代码所示 主界面使用2个控件 HorizontalScrollView ,与 ViewPager 组件,这两种是android SDK中自