2016-01-24 13 views
17

Collapsing ben böyle bir düzen aşağıdaki:CoordinatorLayout RecyclerView ile Ve başlığını

enter image description here

(Araç Çubuğu, Başlık Görünüm, Metin Görünümü, RecyclerView)

ben başlığı gerektiğinde çöktü edilecek Recyclerview öğelerini kaydırıyorum. Böylelikle "Öğe Seç" ve geridönüşüm görünümü ekranda kaldı.

Araç çubuğu daraltıldığında örnekleri gördüm, ancak her zaman mevcut olmak için araç çubuğuna ihtiyacım var.

Bu işi almak için hangi düzeni/davranışı kullanmalıyım?

cevap

34

Bu düzen alarak bunu başarabilir:

<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.design.widget.AppBarLayout 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content"> 

     <android.support.design.widget.CollapsingToolbarLayout 
      android:layout_width="match_parent" 
      android:layout_height="match_parent" 
      app:layout_scrollFlags="scroll|exitUntilCollapsed"> 

      <!-- HEADER --> 
      <RelativeLayout 
       ... 
       app:layout_collapseMode="parallax"> 
       ..... 
      </RelativeLayout> 

      <android.support.v7.widget.Toolbar 
       android:layout_width="match_parent" 
       android:layout_height="?attr/actionBarSize" 
       app:layout_collapseMode="pin" /> 

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

     <!-- IF YOU WANT TO KEEP "Choose Item" always on top of the RecyclerView, put this TextView here 
     <TextView 
      android:layout_width="match_parent" 
      android:layout_height="wrap_content" 
      android:layout_gravity="bottom" 
      android:text="choose item" /> 
     --> 
    </android.support.design.widget.AppBarLayout> 

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

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

Sen app:layout_collapseMode="pin" mülkiyet kümesi sahip olarak araç çubuğunu pin. 'u app:layout_behavior="@string/appbar_scrolling_view_behavior" ayarıyla düzgün bir şekilde kaydırılabilir hale getiriyorsunuz ve bu oldukça fazla.

NB!

  • Eğer RecyclerView kaydırma başlamak kullanıcı kez RecyclerView 'ın Adapter, uzağa kaydırmak için bir ilk element olarak şunları içerebilir: TextView "öğesini seçin" nin pozisyonu ulaşmak istediğiniz belirli davranışlarına bağlı ;
  • AppBarLayout içine ekleyebilirsiniz, böylece her gittiğinizde, her zaman RecyclerView'un üstüne yapışacaktır;

Burada inşallah Design Support Library (III): Coordinator Layout

burada Android Design Support Library daha okuyup olabilir, yardımı olur!

+0

Çok teşekkürler! İşe yarıyor!!! – Oleg

+0

Bir çekicilik gibi çalışır! Teşekkürler – Tooroop

0
The below code is working but not smooth scroll compare reqular recyclerview I thought. 

<?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" 
    xmlns:tools="http://schemas.android.com/tools" 
    android:id="@+id/activity_main" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent"> 


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

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

      <com.sliderbanner.views.BannerSlider 
       android:id="@+id/banner_slider1" 
       android:layout_width="match_parent" 
       android:layout_height="wrap_content" 
       app:animateIndicators="true" 
       app:defaultIndicators="dash" 
       app:interval="5000" 
       app:loopSlides="true" 

       /> 

      <android.support.v7.widget.Toolbar 

       android:id="@+id/toolbar" 
       android:layout_width="match_parent" 
       android:layout_height="?actionBarSize"> 

       <ImageView 
        android:id="@+id/image_github" 
        android:layout_width="36dp" 
        android:layout_height="36dp" 
        android:layout_gravity="right" 
        android:layout_marginRight="8dp" /> 

       <TextView 
        android:layout_width="match_parent" 
        android:layout_height="match_parent" 
        android:fontFamily="sans-serif-bold" 
        android:gravity="center_vertical|left" 
        android:text="Banner Slider" 
        android:textColor="@android:color/black" 
        android:textSize="18sp" /> 
      </android.support.v7.widget.Toolbar> 
     </android.support.design.widget.CollapsingToolbarLayout> 


    </android.support.design.widget.AppBarLayout> 
    <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"> 
    </android.support.v7.widget.RecyclerView> 


</android.support.design.widget.CoordinatorLayout> 
İlgili konular