5

我試圖做這樣的事情:頭佈局上面TabLayout

http://i.imgur.com/NwewaBx.png

我現在有沒有實現的頭上面的佈局。我需要的是找出如何添加標題。

這裏是頭佈局我想把上面的標籤:

<LinearLayout 
    xmlns:android="http://schemas.android.com/apk/res/android" 
    android:orientation="vertical" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent"> 

    <LinearLayout 
     android:id="@+id/header" 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:orientation="vertical" 
     android:layout_gravity="center_horizontal" 
     android:background="@color/green"> 

      <LinearLayout 
       android:orientation="horizontal" 
       android:layout_width="wrap_content" 
       android:layout_height="match_parent" > 

       <ImageView 
        android:layout_width="50dp" 
        android:layout_height="50dp" 
        android:background="@drawable/ic_image" 
        android:adjustViewBounds="true" 
        android:scaleType="centerCrop" 
        android:layout_gravity="center_vertical" /> 

       <TextView 
        android:layout_width="wrap_content" 
        android:layout_height="wrap_content" 
        android:text="Hey!" 
        android:textColor="@color/white" 
        android:textSize="24sp" 
        android:layout_gravity="center_vertical" /> 

      </LinearLayout> 

    </LinearLayout> 

</LinearLayout> 

我用一個RecyclerView的標籤下面的內容。我使用3個不同的Fragments作爲Activity

這裏是我的活動:

​​

這裏是我的一個片段:

<android.support.design.widget.CoordinatorLayout 
    xmlns:android="http://schemas.android.com/apk/res/android" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent"> 

    <android.support.v7.widget.RecyclerView 
     android:id="@+id/recycler_view" 
     android:scrollbars="vertical" 
     android:layout_width="match_parent" 
     android:layout_height="match_parent" 
     /> 

</android.support.design.widget.CoordinatorLayout> 

如何添加上述TabLayout,並保持正常的滾動行爲的頭?

+0

FrameLayout可能對此很有用,因爲您可以將它放置在屏幕的任何位置。所以一種可能的方式來實現這一點 - 沒有工具欄,並使用framelayout,並把它想要的東西,包括其他佈局,把它放在你想要的位置,並在它下面的表格 – Tasos

+0

只有屏幕的內容部分滾動與您的建議。 :/ – user5314557

+0

檢查這個庫 https://github.com/noties/Scrollable – orium

回答

0

你只需要一個RecyclerView來做到這一點。 將您的標題和tabLayout合併到標題視圖,然後添加到您的RecyclerView。

檢查https://github.com/u3breeze/android-RecyclerView-WithHeaderAndFooter。我做了RecyclerView.Adapter的擴展。輕鬆添加頁眉和頁腳到RecyclerView。

+0

重新閱讀我的問題,並看看提供的圖像。你鏈接的不是我要找的東西。 – user5314557