2016-05-27 7 views
0

Ich habe zwei Symbolleisten in meinem Layout, eine, die erweitert und eine darunter. Unter dieser Symbolleiste habe ich mein scrollbares Layout. Layout sieht wie angefügt aus.Coordinator Layout - Ansicht Stick unter erweiterbaren Header

Derzeit habe ich die zweite Symbolleiste im scrollbaren Layout, das heißt, wenn ich im scrollbaren Layout scrolle, verschwindet die zweite Symbolleiste unter der Hauptsymbolleiste. Ich probierte schon mal eine sache, konnte aber folgendes Verhalten nicht bekommen:

Die zweite Symbolleiste (es ist das share_dialog_search_toolbar Layout in meinem Beispiel) sollte IMMER unter der Hauptsymbolleiste bleiben, egal ob die Hauptsymbolleiste erweitert ist oder nicht. Kann mir jemand zeigen, wie das erreicht werden kann?

Ich möchte etwas wie eine zweite Kopfzeile, die unter der erweiterbaren Symbolleiste bleibt.

<android.support.design.widget.CoordinatorLayout 
    xmlns:android="http://schemas.android.com/apk/res/android" 
    xmlns:app="http://schemas.android.com/apk/res-auto" 
    android:background="@color/background_material_light" 
    android:layout_margin="20dp" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent"> 

    <android.support.design.widget.AppBarLayout 
     android:layout_width="match_parent" 
     android:layout_height="250dp" 
     android:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar"> 

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

      <ImageView 
       android:id="@+id/icon" 
       android:layout_width="match_parent" 
       android:layout_height="match_parent" 
       android:scaleType="centerCrop" 
       app:layout_collapseMode="parallax" /> 

      <android.support.v7.widget.Toolbar 
       android:id="@+id/toolbar" 
       android:layout_width="match_parent" 
       android:layout_height="?attr/actionBarSize" 
       android:elevation="4dp" 
       app:layout_collapseMode="pin" 
       app:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar" 
       app:popupTheme="@style/ThemeOverlay.AppCompat.Light" /> 

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

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

    <!-- this toolbar should always be visible underneath the main expandable toolbar in every state --> 
    <include layout="@layout/share_dialog_search_toolbar" app:layout_behavior=".behaviour.SubHeaderBehaviour" /> 

    <android.support.v4.widget.NestedScrollView 
     android:layout_width="match_parent" 
     android:layout_height="match_parent" 
     app:layout_behavior="@string/appbar_scrolling_view_behavior"> 

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

      <FrameLayout 
       android:layout_width="match_parent" 
       android:layout_height="match_parent"> 

       <android.support.v7.widget.RecyclerView 
        android:id="@+id/rvData" 
        android:layout_width="match_parent" 
        android:layout_height="match_parent" 
        android:scrollbars="vertical" /> 

       <ProgressBar 
        style="?android:attr/progressBarStyle" 
        android:layout_width="wrap_content" 
        android:layout_height="wrap_content" 
        android:padding="15dp" 
        android:id="@+id/pbLoading" 
        android:layout_gravity="center" 
        android:indeterminate="true" /> 

      </FrameLayout> 

     </LinearLayout> 

    </android.support.v4.widget.NestedScrollView> 

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

Mit folgenden SubHeaderBehaviour:

public class SubHeaderBehaviour extends CoordinatorLayout.Behavior<LinearLayout> 
{ 
    public SubHeaderBehaviour(Context context, AttributeSet attrs) 
    { 
    } 

    @Override 
    public boolean layoutDependsOn(CoordinatorLayout parent, LinearLayout child, View dependency) { 
     return dependency instanceof AppBarLayout; 
    } 

    @Override 
    public boolean onDependentViewChanged(CoordinatorLayout parent, LinearLayout child, View dependency) 
    { 
     // always move child under dependency... does not work though 
     child.setY(dependency.getY() + dependency.getHeight()); 
     return true; 
    } 
} 

Dieses Verhalten überhaupt nicht funktioniert, bleibt der Blick nur auf immer ...

EDIT

Sorry, Dies funktioniert mit dem benutzerdefinierten Verhalten. Das Problem war, ich habe Merge in meinem Such-Toolbar-Layout verwendet. Direkt hinzuzufügen, wirkt wie ein Zauber. Ich muss nur noch das Padding der Scroll-Ansicht anpassen, um den Platz meines Sub-Headers zu verlassen.

Antwort

0
<android.support.design.widget.AppBarLayout 
    android:layout_width="match_parent" 
    android:layout_height="250dp" 
    android:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar"> 

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

     <ImageView 
      android:id="@+id/icon" 
      android:layout_width="match_parent" 
      android:layout_height="match_parent" 
      android:scaleType="centerCrop" 
      app:layout_collapseMode="parallax" /> 

     <android.support.v7.widget.Toolbar 
      android:id="@+id/toolbar" 
      android:layout_width="match_parent" 
      android:layout_height="?attr/actionBarSize" 
      android:elevation="4dp" 
      app:layout_collapseMode="pin" 
      app:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar" 
      app:popupTheme="@style/ThemeOverlay.AppCompat.Light" /> 

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

    <include layout="@layout/share_dialog_search_toolbar" /> 

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

Ich bin mir ziemlich sicher, dass ich das versucht habe. Ich werde es später nochmal versuchen. Aber ich brauche das, um mit der Suchsymbolleiste UND der Scroll-Ansicht darunter zu arbeiten ... – prom85

+0

Wenn das nicht funktioniert, versuche die share_dialog_search_toolbar mit einem framelayout zu umhüllen –

+0

Das alles scheitert. Es wird nicht unter der Symbolleiste bleiben, wenn die Bildlaufansicht gescrollt wird ... Egal wie ich es eingerichtet habe. Ich denke, ich muss entweder ein benutzerdefiniertes Verhalten oder eine Art Anker, aber konnte noch nicht arbeiten – prom85

Verwandte Themen