1
Scrollen

ich die kollabierenden Symbolleiste in einem meiner Aktivitäten umgesetzt und auf die Symbolleiste Scrollen nicht kollabiert:Einstürzen Symbolleiste und recyclerview nicht kollabiert, wenn

<?xml version="1.0" encoding="utf-8"?> 
<android.support.v4.widget.SwipeRefreshLayout 
    xmlns:android="http://schemas.android.com/apk/res/android" 
    android:id="@+id/swipeContainer" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent"> 

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    xmlns:app="http://schemas.android.com/apk/res-auto" 
    android:background="@color/white" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    android:orientation="vertical"> 

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

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

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

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

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


</LinearLayout> 
</android.support.v4.widget.SwipeRefreshLayout> 

ich auch die erforderlichen Bibliotheken hinzugefügt Gradle. Die Symbolleiste bleibt beim Abwärtsscrollen an der gleichen Stelle. Irgendeine Idee, warum das passiert?

Antwort

1

Das AppBarLayout benötigt das CoordinatorLayout.

Diese Ansicht hängt stark davon ab, dass sie als direktes Kind in einem CoordinatorLayout verwendet wird. Wenn Sie AppBarLayout in einer anderen ViewGroup verwenden, funktionieren die meisten Funktionen nicht.

von developer.android.com/reference/android/support/design/widget/AppBarLayout.html Zitat

einen Blick auf diese Tutorials auch: http://antonioleiva.com/collapsing-toolbar-layout/

+0

Ich habe ein anderes Layout innerhalb dieser recyclerview –

+0

@RainMan: Sie haben nicht ein Linearlayout in diesen benötigen. CoordinatorLayout wird die Ansichten basierend auf ihrem Verhalten entsprechend positionieren. Entferne das 'LinearLayout', bewege das' SwipeRefreshLayout' um den 'RecyclerView', und mache dann die oberste Ebene'CoordinatorLayout'. – DeeV

+0

@DeeV, danke für den Kommentar, ich habe die gleiche Methode wie Sie beschrieben, aber jetzt, wenn der Inhalt von recycleview über der Symbolleiste ist. –

1

Dieser Code kann Ihnen helfen Definieren Sie CollapingsToolbar in Ihrer Aktivität und schreiben Sie die Methode zum Erweitern und Reduzieren.

<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:id="@+id/activity_car_tracker" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    android:fitsSystemWindows="true"> 

    <android.support.v7.widget.RecyclerView 
     android:id="@+id/recycler" 
     android:layout_width="match_parent" 
     android:layout_height="match_parent" 
     app:layout_behavior="@string/appbar_scrolling_view_behavior" 
     tools:context="com.example.user.Activity" /> 

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

     <android.support.design.widget.CollapsingToolbarLayout 
      android:id="@+id/collapsing_toolbar" 
      android:layout_width="match_parent" 
      android:layout_height="match_parent" 
      android:background="@color/toolbarbackgroundcolor" 
      android:fitsSystemWindows="true" 
      app:layout_scrollFlags="scroll|exitUntilCollapsed"> 

      <android.support.v7.widget.Toolbar 
       android:id="@+id/toolbar" 
       android:layout_width="match_parent" 
       android:layout_height="?attr/actionBarSize" 
       android:background="@color/toolbarbackgroundcolor" 
       android:minHeight="?attr/actionBarSize" 
       app:layout_collapseMode="pin" 
       app:popupTheme="@style/ThemeOverlay.AppCompat.Light"/> 

       <ImageView 
        android:layout_width="match_parent" 
        android:layout_height="match_parent" 
        android:layout_gravity="center" 
        android:foregroundGravity="center" 
        android:src="@drawable/location" 
        android:scaleType="centerCrop" 
        app:layout_collapseMode="parallax"/> 

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



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