微信作为面向大众的产品,它的界面一直保持简洁的风格,实现布板的主界面时也参考了很多APP的设计,最终决定采用类似于微信的主界面,即四个tab滑动。
google了一把之后,找到了一款滑动利器PagerSlidingTabStrip。
官网地址:https://github.com/astuetz/PagerSlidingTabStrip
官方效果图如下:
但使用过程中发现想要把滑动tab放到底部更改布局相当麻烦,后来自己思考并结合了guolin大神的一篇介绍Fragment的文章 Android Fragment应用实战,使用碎片向ActivityGroup说再见,终于完美地实现了想要的效果,如下是最终的效果图:
首先新建一个activity_main.xml布局文件,代码如下:
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools= "http://schemas.android.com/tools"
xmlns:pagerslidingtabstrip="http://schemas.android.com/apk/res-auto"
android:layout_width= "match_parent"
android:layout_height= "match_parent"
android:background= "@color/mainbackground"
android:clipChildren= "false"
android:clipToPadding= "false"
>
<com.astuetz.PagerSlidingTabStrip
android:id= "@+id/mainTabs"
android:layout_width="match_parent"
android:layout_height="10dp"
android:visibility="gone"
/>
<android.support.v4.view.ViewPager
android:id= "@+id/mainPager"
android:layout_width="match_parent"
android:layout_height="match_parent"
/>
<LinearLayout
android:layout_alignParentBottom="true"
android:layout_width="match_parent"
android:layout_height="50dp"
android:clipChildren="false"
android:clipToPadding= "false"
android:background= "@color/mainbackground"
android:baselineAligned= "false"
>
<LinearLayout
android:id= "@+id/onlyYou"
android:layout_width="0dp"
android:layout_weight="1"
android:layout_height="match_parent"
android:gravity="center"
android:orientation="vertical"
>
<ImageView
android:id= "@+id/onlyYouImage"
android:layout_width="25dp"
android:layout_height="25dp"
/>
<TextView
android:id= "@+id/onlyYouText"
android:textSize="10sp"
android:text="@string/onlyyou"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
/>
</LinearLayout>
<LinearLayout
android:id= "@+id/guang"
android:layout_width=