今儿在项目中遇到个问题,分析了下采用Fragment解决。
1.问题描述:
如图所示,在页面顶部有4个tab要求支持切换,以及页面滑动时tab切换。
2.解决方案分析
2.1 tab切换:为了让每一个tab页都有一个完整的生命周期,决定采用Fragment去编写。
2.2 滑动切换:ViewPagger
3.解决方法
3.1 主容器
task_add_activity.xml
<?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" >
<android.support.v4.view.ViewPager
android:id="@+id/viewPager"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
andro