2016-07-10 5 views
1

Панель инструментов перекрывает содержимое, которое содержит LinearLayout, а затем LinearLayout содержит фрейммент &. Почему?ToolBar перекрывает содержимое (LinearLayout), которое содержит фрагменты

Я использую Android Studio 2.2 Предварительный просмотр 5.

<?xml version="1.0" encoding="utf-8"?> 
<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="match_parent" 
    android:fitsSystemWindows="true" 
    tools:context="com.example.popularmovies2.MainActivity"> 

    <android.support.design.widget.AppBarLayout 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:theme="@style/AppTheme"> 

     <android.support.v7.widget.Toolbar 
     android:id="@+id/toolbar" 
     android:layout_width="match_parent" 
     android:layout_height="?attr/actionBarSize" 
     android:background="?attr/colorPrimary" 
     app:popupTheme="@style/AppTheme" /> 

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

    <LinearLayout 
     android:layout_width="match_parent" 
     android:layout_height="match_parent" 
     android:baselineAligned="false" 
     android:divider="?android:attr/dividerHorizontal" 
     android:orientation="horizontal" 
     tools:context="com.example.popularmovies2.MainActivity"> 

     <fragment 
      android:id="@+id/fragment" 
      android:name="com.example.popularmovies2.MainActivityFragment" 
      android:layout_width="0dp" 
      android:layout_height="match_parent" 
      android:layout_weight="2" 
      tools:layout="@android:layout/list_content" /> 

     <FrameLayout 
      android:id="@+id/movie_detail_fragment" 
      android:layout_width="0dp" 
      android:layout_height="match_parent" 
      android:layout_weight="4" /> 

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

Я добавление изображения для справки. Пожалуйста, посмотрите & руководство.

image

ответ

12

CoordinatorLayout действует как FrameLayout. Он перекрывает своих детей. Wrap AppBarLayout и LinearLayout с другим вертикальным линейным макете, как это:

<?xml version="1.0" encoding="utf-8"?> 
<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="match_parent" 
    android:fitsSystemWindows="true" 
    tools:context="com.example.popularmovies2.MainActivity"> 

    <LinearLayout 
     android:layout_width="match_parent" 
     android:layout_height="match_parent" 
     android:orientation="vertical"> 

    <android.support.design.widget.AppBarLayout 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:theme="@style/AppTheme"> 

     <android.support.v7.widget.Toolbar 
     android:id="@+id/toolbar" 
     android:layout_width="match_parent" 
     android:layout_height="?attr/actionBarSize" 
     android:background="?attr/colorPrimary" 
     app:popupTheme="@style/AppTheme" /> 

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

    <LinearLayout 
     android:layout_width="match_parent" 
     android:layout_height="match_parent" 
     android:baselineAligned="false" 
     android:divider="?android:attr/dividerHorizontal" 
     android:orientation="horizontal" 
     tools:context="com.example.popularmovies2.MainActivity"> 

     <fragment 
      android:id="@+id/fragment" 
      android:name="com.example.popularmovies2.MainActivityFragment" 
      android:layout_width="0dp" 
      android:layout_height="match_parent" 
      android:layout_weight="2" 
      tools:layout="@android:layout/list_content" /> 

     <FrameLayout 
      android:id="@+id/movie_detail_fragment" 
      android:layout_width="0dp" 
      android:layout_height="match_parent" 
      android:layout_weight="4" /> 

    </LinearLayout> 
</LinearLayout> 
</android.support.design.widget.CoordinatorLayout> 
+0

спасибо. Это сработало. –

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