2014-11-10 37 views
7

Gần đây tôi đã bắt đầu rối tung với các thành phần mới của AppCompat 21 và triển khai Thiết kế Material Design. Hiện tại, tôi có một ActionBarActivity với một Thanh công cụ và đang cố gắng để nó lưu trữ một đoạn có chứa một RecyclerView của các mục TextView (chỉ để kiểm tra Recycler). Tôi có các mục được hiển thị, nhưng các văn bản trong mỗi điểm được cắt đứt và toàn bộ Recycler là bao gồm các thanh công cụ như vậy:Nội dung phân đoạn đang che phủ Thanh công cụ

e description here

Như bạn có thể thấy, có ba TextView. Văn bản của họ bị cắt nửa chừng và nó che phủ Thanh công cụ (không có Tiêu đề tôi biết). Bố cục mục TextView được chứa trong một bố cục RecyclerView, đó là bố cục của Phân đoạn. Hoạt động gốc có FrameLayout -> Toolbar, FrameLayout. Tôi đang chèn Fragment vào FrameLayout phụ của Activity. Đây là XML:

Mỗi xem trong 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"/> 

Cách bố trí Recycler, đó là cách bố trí của các 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> 

Và bố trí các Hoạt động của cha mẹ:

<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> 

Tôi biết nó phải là một cái gì đó đơn giản nhưng tôi đã stumped trên nó một lúc, cố gắng những thứ khác nhau để không ava Il.

Trả lời

8

Sử dụng RelativeLayout thay vì FrameLayout làm cha mẹ hàng đầu. Sau đó, chỉ cần thêm các phụ thuộc như layout_above cho Toolbar hoặc layout_below cho vùng chứa phân đoạn.

21

Xin đừng quên thêm ứng dụng: layout_behavior = "@ string/appbar_scrolling_view_behavior" để bố trí nội dung của bạn

<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

này nên là câu trả lời đúng ... – josemigallas

Các vấn đề liên quan