2016-04-04 4 views
2

Я использую TabLayout, и я прикладываю две вкладки.Содержание фрагмента над текстом Tab в TabLayout

tabLayout.addTab(tabLayout.newTab().setText("Featured")); 
    tabLayout.addTab(tabLayout.newTab().setText("Filter")); 

Затем onTabSelected() я показываю фрагмент я хочу, согласно которому вкладка пользователь выбрал.

Компоновка моей деятельности является:

<LinearLayout 
    xmlns:android="http://schemas.android.com/apk/res/android" 
    xmlns:app="http://schemas.android.com/apk/res-auto" 
    android:id="@+id/ll_container" 
    android:orientation="vertical" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent"> 


    <android.support.design.widget.TabLayout 
     android:id="@+id/tabs" 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     app:tabMode="fixed" 
     app:tabGravity="fill"/> 

    <FrameLayout 
     android:id="@+id/fl_content" 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content"/> 

</LinearLayout> 

и расположение фрагментов просто TextView в LinearLayout:

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

    <TextView 
     android:text="Projects List Fragment" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" /> 

</LinearLayout> 

Но результат я получаю следующее:

enter image description here

Как вы можете видеть содержание fra gment перекрывает текст Tab, когда он должен появляться под ним. Спасибо

+0

Использование 'RelativeLayout' в виде точки зрения и' android: layout_below' в 'FrameLayout' – Mohit

+0

@Mohit просто попробовал, и это не сработало. – Mes

+0

напишите код, в котором вы вызываете фрагмент –

ответ

2

Наконец, я нашел альтернативное решение этой проблемы.

Вы можете указать верхнюю прописку на макете каждого фрагмента вкладки.

Например,

андроид: "атр/actionBarSize" paddingTop =

Например, моя первая вкладка XML выглядит следующим образом:

<android.support.design.widget.CoordinatorLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    xmlns:app="http://schemas.android.com/apk/res-auto" 
    xmlns:tools="http://schemas.android.com/tools" 
    android:layout_width="match_parent" 
    android:layout_height="wrap_content" 
    android:paddingTop="?attr/actionBarSize" 
    app:layout_behavior="@string/appbar_scrolling_view_behavior" 
    tools:context="com.upgautam.uddhav.productassignment.uicontrollers.ProductListFragment"> 

    <TextView 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:text="@string/product_list_string" /> 

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

Теперь экран выглядит следующим образом: enter image description here

Смежные вопросы