9

Ich entwickle eine Android-App mit der neuen Design-Bibliothek. Ich möchte einen ähnlichen Scroll-Effekt erstellen, der in der neuen Google Photos app verwendet wird. Ich möchte, dass das AppBarLayout vollständig vom Bildschirm wegscrollt, so dass die Recycleransicht hinter der Statusleiste angezeigt wird.So machen Sie AppBarLayout vollständig verschwinden mit windowTranslucentStatus auf True gesetzt

Ich habe windowTranslucentStatus im App-Thema auf true gesetzt. Hier ist die xml der Haupttätigkeit:

<?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" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent"> 

    <android.support.v7.widget.RecyclerView 
     android:id="@+id/recyclerView" 
     android:layout_width="match_parent" 
     android:layout_height="match_parent" 
     app:layout_behavior="@string/appbar_scrolling_view_behavior" /> 

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

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

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

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

Hier ist, wie das aussieht, wenn nach unten gescrollt: Toolbar not disappearing completely

Die Toolbar nicht vollständig verschwinden.

Vielen Dank für Ihre Hilfe!

+1

Ich fange an zu fragen, ob sie auch die CoordinatorLayout verwendet ... Ich Ich habe den ganzen Tag über genau diese Frage gestellt. – timothyjc

+0

@timothyjc Wenn Sie eine Lösung vor mir finden, können Sie es bitte hier posten. Und ich denke, Sie haben Recht ja – alesko007

+0

Uploaded mein Beispiel-Projekt zu Github für den Fall, dass jemand das Problem leicht sehen will ... https://github.com/timothyjc/TestALot – timothyjc

Antwort

0

Das war ungefähr so ​​nah wie ich mit dem CoordinatorLayout (nur das Spiel mit den Rand in der Symbolleiste) bekommen könnte ... schließen nicht genug imo:

<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:fitsSystemWindows="true" 
    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.support.v7.widget.Toolbar 
     android:id="@+id/toolbar" 
     android:paddingTop="25dp" 
     android:layout_width="match_parent" 
     android:layout_height="81dp" 
     android:layout_marginTop="-28dp" 
     android:background="#00ffffff" 
     app:layout_scrollFlags="scroll|enterAlways" /> 

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

<android.support.v7.widget.RecyclerView 
    android:id="@+id/recyclerview" 
    android:background="#ffffff" 
    android:fitsSystemWindows="true" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    app:layout_behavior="@string/appbar_scrolling_view_behavior" /> 


<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="16dp" 
    android:src="@drawable/ic_headphones_white_24dp" /> 

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

Ich denke, dass es leichter sein wird, es zu tun manuell ...

Haben Sie irgendwelche Ideen oder Fortschritte?

+0

Ich versuche etwas mit der Einstellung von Höhe und Rändern zu koordinieren Layout. Dies schafft jedoch neue Probleme. Hast du es herausgefunden? – alesko007

+0

Irgendein Typ auf Reddit hat mir gesagt, dass es einen Bug gibt und es wird nächste Version der Support-Design-Lib behoben werden. Ich habe alle Animationen manuell gemacht. – timothyjc

+0

@timothyjc fitsSystemWindows muss auch auf dem AppBarLayout sein. and android: windowDrawsSystemBarBackgrounds = true sollte in v-21 sein styles.xml Dies ist, was ich getan habe, damit es funktioniert. – Suleiman19

-1

Fügen Sie pastsSystemWindows = "true" für Ihr AppBarLayout und CoordinatorLayout hinzu.


+0

Das funktioniert nicht – alesko007

+0

Das macht die Toolbar nicht transparent. –

0

In meinem Fall habe ich fitSystemWindows = "false" zu CoordinatorLayout und fitSystemWindows = "true" zu seinem Kind - in Ihrem Fall der RecyclerView. Auf NavigationView, DrawerLayout, AppBarLayout und Toolbar ist es "wahr". Ich habe verschiedene Werte ausprobiert und dann ist bei mir etwas kaputt. Android 5.1.1 und die neuesten Support-Bibliotheken (23.0.1). Ich hoffe es hilft.

1

Hier ist, was ich in meiner Anwendung verwendet

<android.support.design.widget.AppBarLayout 
    android:id="@+id/app_bar" 
    android:layout_width="match_parent" 
    android:layout_height="@dimen/app_bar_height" 
    android:fitsSystemWindows="true" 
    android:theme="@style/AppTheme.AppBarOverlay"> 

    <android.support.design.widget.CollapsingToolbarLayout 
     android:id="@+id/toolbar_layout" 
     android:layout_width="match_parent" 
     android:layout_height="match_parent" 
     android:fitsSystemWindows="true" 
     app:contentScrim="?attr/colorPrimary" 
     app:layout_scrollFlags="scroll|enterAlwaysCollapsed"> 

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

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

Verwenden gemeinsames Muster von AppBarLayout, die aus der App-Vorlage kommt, wenn Sie ein Android-Projekt in Android Studio erstellen. Nur wenige Änderungen im XML-Layout und Java-Code:

XML Layout:

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

    <FrameLayout 
     android:id="@+id/toolbar_container" 
     android:fitsSystemWindows="true" 
     app:layout_scrollFlags="scroll|enterAlways" 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:background="?attr/colorPrimary" 
     > 

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

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

Java-Code:

ViewCompat.setOnApplyWindowInsetsListener(toolbar, new OnApplyWindowInsetsListener() { 
     @Override 
     public WindowInsetsCompat onApplyWindowInsets(View v, WindowInsetsCompat insets) { 
      toolbarContainerLayout.setPadding(0, insets.getSystemWindowInsetTop(), 0, 0); 

      return insets; 
     } 
    });