2015-01-03 152 views
3

我所試圖做的事:將viewpager裏面片段滑動標籤爲嵌套格式

  1. 我使用的抽屜裏,我有10個片段
  2. 裏面我努力的片段之一添加視圖尋呼機與 滑動片(具有圖尋呼機指示器按照傑克沃頓)

正在發生的事情:

  1. ,當我試圖做到這一點,我得到error as described here in one of my other stackoverflow question
  2. 我不能把圖中的 描述的架構之下

問題: :

  1. 是否在放置 碎片時不能使用滑動標籤查看尋呼機?
  2. 如果有,還有網上樣品嗎? (傑克沃頓樣品進行 與放置部件在活動不片段)
  3. 如果有任何其他的方式可以在那裏爲 任何開源庫,這個

注:我是意識到嵌套的方式不建議,但我需要得到這個架構


架構我試圖得到它:

fig

+0

你有沒有解決這個問題? – Urchin

回答

1

起初,你可以從谷歌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(); 
相關問題