2014-11-10 23 views
7

Niedawno zacząłem bawić się nowymi komponentami AppCompat 21 i wdrażaniem Material Design. Obecnie mam ActionBarActivity z Paskiem Narzędzi i próbuję go hostować fragment zawierający RecyclerView z elementów TextView (tylko po to, aby przetestować Recycler). Muszę być wyświetlane elementy, ale tekst w każdym widoku jest odcięta i cała Recycler zakrywa pasek tak:Treść fragmentów nakłada się na pasek narzędzi

e description here

Jak widać, istnieją trzy TextView. Ich tekst jest odcięty w połowie i nakłada się na pasek narzędzi (brak tytułu, który znam). Układy elementów TextView są zawarte w układzie RecyclerView, który jest układem Fragmentu. Nadrzędna aktywność ma FrameLayout -> Toolbar, FrameLayout. Wstawiam Fragment do Sub FrameLayout Activity. Oto XML:

Każdy widok w Recycler:

<TextView 
    xmlns:android="http://schemas.android.com/apk/res/android" 
    android:id="@+id/textview" 
    android:layout_width="match_parent" 
    android:layout_height="48dp" 
    android:fontFamily="sans-serif" 
    android:paddingTop="16dp" 
    android:paddingBottom="20dp" 
    android:textSize="16sp"/> 

układ Recycler, którym jest układ Fragment:

<android.support.v7.widget.RecyclerView 
    xmlns:android="http://schemas.android.com/apk/res/android" 
    xmlns:tools="http://schemas.android.com/tools" 
    android:id="@+id/recycler_tasks" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    tools:context="stuff.MainActivity$TaskFragment"> 
</android.support.v7.widget.RecyclerView> 

i układ nadrzędnego Activity za:

<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    xmlns:tools="http://schemas.android.com/tools" 
    xmlns:app="http://schemas.android.com/apk/res-auto" 
    android:id="@+id/container" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    tools:context=".MainActivity" 
    tools:ignore="MergeRootFrame"> 

    <android.support.v7.widget.Toolbar 
    android:id="@+id/toolbar" 
    android:layout_height="wrap_content" 
    android:layout_width="match_parent" 
    android:minHeight="?attr/actionBarSize" 
    android:background="?attr/colorPrimary" 
    app:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar" 
    app:popupTheme="@style/ThemeOverlay.AppCompat.Light"/> 

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

</FrameLayout> 

Wiem, że to musi być coś prostego, ale od pewnego czasu jestem na niego zakłopotany, próbując różnych rzeczy bez żadnej ava il.

Odpowiedz

8

Użyj RelativeLayout zamiast FrameLayout jako najwyższego rodzica. Następnie dodaj do kontenera fragmentów takie zależności, jak layout_above dla Toolbar lub.

21

Proszę nie zapomnij dodać aplikację: layout_behavior = "@ ciąg/appbar_scrolling_view_behavior" do układu zawartości

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

<android.support.design.widget.AppBarLayout 
    android:layout_width="match_parent" 
    android:layout_height="wrap_content" 
    android:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar"> 

    <android.support.v7.widget.Toolbar 
     android:layout_width="match_parent" 
     android:layout_height="?attr/actionBarSize" 
     android:background="?attr/colorPrimary" 
     app:layout_scrollFlags="scroll|enterAlways" 
     app:popupTheme="@style/ThemeOverlay.AppCompat.Light" /> 

     <android.support.design.widget.TabLayout 
      android:layout_width="match_parent" 
      android:layout_height="wrap_content" /> 

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

    <android.support.v4.view.ViewPager 
     android:layout_width="match_parent" 
     android:layout_height="match_parent" 
     app:layout_behavior="@string/appbar_scrolling_view_behavior" /> 

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

To powinno być prawidłowa odpowiedź ... – josemigallas

Powiązane problemy