起初,你可以從谷歌https://developer.android.com/samples/SlidingTabsBasic/project.html試試這個樣品。它還包含SlidingTabLayout類,嘗試它,如果你使用不同的東西。
該項目類似於您的(具有相同的佈局),除了導航抽屜。
所以,讓我們做以下事情:
主佈局可能看起來像這樣:
<android.support.v4.widget.DrawerLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/drawer_layout"
android:layout_width="match_parent"
android:layout_height="match_parent">
<FrameLayout
android:id="@+id/content_fragment"
android:layout_width="match_parent"
android:layout_height="match_parent" />
<LinearLayout
android:id="@+id/drawer"
android:layout_width="@dimen/drawer_width"
android:layout_height="match_parent"
android:layout_gravity="left"
android:background="@color/drawer_back"
android:gravity="left|center_vertical"
android:orientation="vertical">
<ListView
android:id="@+id/left_drawer"
android:layout_width="@dimen/drawer_width"
android:layout_height="0dip"
android:layout_gravity="left"
android:layout_weight="1"
android:background="@color/drawer_back"
android:choiceMode="singleChoice"
android:clipToPadding="false"
android:divider="@android:color/darker_gray"
android:dividerHeight="1dp" />
</LinearLayout>
</android.support.v4.widget.DrawerLayout>
對於片段與滑動接頭使用以下佈局:
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<yourpackage.slidinglayout.SlidingTabLayout
android:id="@+id/sliding_tabs"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="?attr/colorPrimary"/>
<View
android:layout_width="match_parent"
android:layout_height="4dp"
android:background="@drawable/toolbar_shadow" />
<android.support.v4.view.ViewPager
android:id="@+id/viewpager"
android:layout_width="match_parent"
android:layout_height="0px"
android:layout_weight="1"
android:layout_marginTop="@dimen/small_padding"
android:background="@android:color/white"/>
</LinearLayout>
之後你應該爲你的ViewPager創建一個碎片等,但我認爲,你已經完成了。
滑動標籤和ViewPager的片段 - 這取決於你。
在抽屜項目滑動點擊選項卡,使用簡單的FragmentTransaction:
mCurrentFragment = new SlidingTabsFragment();
mTransaction.replace(R.id.content_fragment, mCurrentFragment);
mTransaction.commit();
你有沒有解決這個問題? – Urchin