9

ich das Layout unten bin mit, hält die CoordinatorLayout Inneren AppBarLayout (Mit Toolbar und TabLayout im Innern) und ein Platzhalter RelativeLayout, so konnte ich Fragmente auf sie hinzufügen und ersetzen.CoordinatorLayout mit Toolbar und Fragmente

Ich habe Marginfehler, die Fragmente, die ich auf dem RelativeLayout hinzufüge, werden immer über den unteren Bildschirmrand hinaus ausgedehnt (in der Höhe ähnlich der Größe der AppBarLayout Höhe), ich habe versucht, die Höhe einzustellen wrap_content und match_parent, in beiden Fällen geht es über Bord.

Wenn ich die app:layout_behavior="@string/appbar_scrolling_view_behavior" aus der RelativeLayout entfernen, wird die Oberseite davon unter der AppBarLayout sein, die auch nicht das gewünschte Ergebnis ist.

<android.support.v4.widget.DrawerLayout xmlns:android="http://schemas.android.com/apk/res/android" 
xmlns:app="http://schemas.android.com/apk/res-auto" 
android:id="@+id/drawer_layout" 
android:layout_height="match_parent" 
android:layout_width="match_parent" 
android:fitsSystemWindows="true"> 

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

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

     <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/ThemeOverlay.AppCompat.Light" 
       app:layout_scrollFlags="scroll|enterAlways" /> 

      <android.support.design.widget.TabLayout 
       android:id="@+id/tabs" 
       app:tabIndicatorHeight="4dp" 
       app:tabIndicatorColor="#ffffff" 
       app:tabMode="scrollable" 
       android:visibility="gone" 
       android:layout_width="match_parent" 
       android:layout_height="wrap_content" /> 

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


     <RelativeLayout 
      app:layout_behavior="@string/appbar_scrolling_view_behavior" 
      android:id="@+id/main_fragment_container" 
      android:layout_width="match_parent" 
      android:layout_height="wrap_content"/> 


     <android.support.design.widget.FloatingActionButton 
      android:id="@+id/fab" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:layout_gravity="end|bottom" 
      android:layout_margin="20dp" 
      android:src="@drawable/ic_done" /> 


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

<android.support.design.widget.NavigationView 
    android:id="@+id/nav_view" 
    android:layout_height="match_parent" 
    android:layout_width="wrap_content" 
    android:layout_gravity="start" 
    android:fitsSystemWindows="true" 
    app:headerLayout="@layout/nav_header" 
    app:menu="@menu/drawer_view"/> 

</android.support.v4.widget.DrawerLayout> 
+0

Können Sie ein besseres Beispiel geben? Das 'RelativeLayout' tut nichts und hat eine Höhe von technisch' 0' wegen 'wrap_content', es sei denn, Sie machen programmatisch etwas damit. Wenn Sie es als "Container" verwenden möchten, verwenden Sie ein 'FrameLayout'. –

+0

Ich setze ein Fragment darauf, mache eine Fragmenttransaktion und stelle die ID des RelativeLayouts zur Verfügung, ich habe auch versucht, FrameLayout dasselbe Ergebnis zu verwenden. – Calc

+0

Es ist offensichtlich, dass Sie dies aus Chris Banes Beispiel erhalten haben: https://github.com/chrisbanes/cheesesquare/blob/master/app/src/main/res/layout/include_list_viewpager.xml. Beachten Sie, dass sein 'ViewPager'' match_parent' verwendet? –

Antwort

0

Das Problem wurde durch die Aktualisierung der recyclerview Bibliothek (bis com.android.support:recyclerview-v7:22.2.0)

Das Fragment I laden recyclerview hatte darin war gelöst.

2

Sie werden dieses Problem auch sehen, wenn Sie eine ScrollView innerhalb des Fragments haben. So stellen Sie sicher, dass Sie eine NestedScrollView verwenden stattdessen:

<android.support.v4.widget.NestedScrollView 
xmlns:android="http://schemas.android.com/apk/res/android" 
android:layout_width="match_parent" 
android:layout_height="match_parent"> 
+0

Was ist mit LinearLayout? Ich habe ein ähnliches Problem damit. – Calc

+0

Können Sie es in eine NestedScrollView einbinden? – bkurzius

3

ich das Problem zu zeigen Fragment unter Symbolleiste herausgefunden haben, wenn der Koordinator Layout. Das Problem in meinem Fall ist:

In this image it shows the Fragment is overlapped by Toolbar.

Nun setzen Sie Ihre AppBarLayout und FrameLayout gerade innerhalb Linearlayout unten wie

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

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

      <android.support.v7.widget.Toolbar 
       android:id="@+id/toolbar" 
       android:layout_width="match_parent" 
       android:layout_height="?attr/actionBarSize" 
       android:background="?attr/colorPrimary" 
       app:layout_scrollFlags="scroll|enterAlways"/> 

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

     <FrameLayout 
      android:id="@+id/frame_container" 
      android:layout_width="match_parent" 
      android:layout_height="match_parent"/> 
    </LinearLayout> 

Jetzt ist Ihr Problem gelöst ist. Und so wird es sein.

The final image.

+0

'AppBarLayout' sollte ein direktes Kind eines' CoordinatorLayout' sein. Siehe: http://developer.android.com/reference/android/support/design/widget/AppBarLayout.html – Orbit

1

hatte das gleiche Problem. Das Ändern von zu FrameLayout mit Parameter app:layout_behavior="@string/appbar_scrolling_view_behavior" löste mein Problem.

<FrameLayout 
    android:id="@+id/main_fragment_container" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    app:layout_behavior="@string/appbar_scrolling_view_behavior"/> 
Verwandte Themen