2015-06-17 5 views
9

in meinem activity_main.xml inklusive ‚s DrawerLayout ist ein CoordinatorLayout genannt content_layout.xml. Innerhalb dieser CoordinatorLayout ist meine AppBarLayout enthält eine Toolbar, dann eine LinearLayout für den Inhalt eines Fragments.CoordinatorLayout Toolbar unsichtbar auf Eingabe bis zur vollständigen Höhe

Wenn ein Fragment mit einem RecyclerView nach oben gescrollt wird, wird die Symbolleiste erfolgreich beendet. Das Problem liegt beim Scrollen nach unten, um die Symbolleiste zurück zu bringen. Die Symbolleiste wird nicht angezeigt, bis die gesamte Höhe der Symbolleiste gescrollt wurde und als solche ein unansehnliches weißes Feld an ihrer Stelle, wie gezeigt, hinterlässt.

toolbar http://i59.tinypic.com/33xil5d.png

content_layout.xml

<android.support.design.widget.CoordinatorLayout 
    xmlns:app="http://schemas.android.com/apk/res-auto" 
    xmlns:android="http://schemas.android.com/apk/res/android" 
    android:id="@+id/container_frame" 
    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" 
      app:layout_scrollFlags="scroll|enterAlways" 
      app:popupTheme="@style/ThemeOverlay.AppCompat.Light" /> 

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

    <!-- The main content view for fragments--> 
    <LinearLayout 
     android:id="@+id/content_frame" 
     android:layout_width="match_parent" 
     android:layout_height="match_parent" 
     android:orientation="vertical" 
     app:layout_behavior="@string/appbar_scrolling_view_behavior"/> 

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

Die Symbolleiste onCreate() über MainActivity ‚s initialisiert wird:

Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar); 
setSupportActionBar(toolbar); 
getSupportActionBar().setHomeButtonEnabled(true); 
getSupportActionBar().setDisplayHomeAsUpEnabled(true); 

Ich würde keine Vorschläge zur Lösung dieses zu schätzen wissen. Vielen Dank.

Antwort

13

Ich hatte das gleiche Problem und das einzige, was ich fand, dass es gelöst wurde, war etwas anderes als die toolbar innerhalb der AppBarLayout. Ich habe eine unsichtbare Ansicht in mein Layout unter der Symbolleiste platziert. Nicht die ideale Lösung, aber es hat funktioniert.

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

    <View 
     android:id="@+id/appbar_bottom" 
     android:layout_width="match_parent" 
     android:layout_height="1dp" 
     android:background="@android:color/transparent" 
     android:visibility="invisible"/> 

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

Das ist brilliant, danke! Funktioniert super. Obwohl, wie du, bin ich mir nicht ganz sicher warum. – McGuile

+0

Super thx dafür. Sie können Höhe auch auf 0,1dp setzen, so dass es gar nicht sichtbar ist (naja; fast überhaupt;)) – zoroz

+1

Vielen Dank @Jon Cordeiro –

Verwandte Themen