7

Bunu uygulamak için biraz zaman harcadım, ve biraz araştırma yaptım ama işe yaramayacaktım. Chris Banes tarafından yapılan cheesesquare örneğinde, ViewPager öğesi kaydırıldığında araç çubuğunun kaydırılmasını sağlar. ViewPager doğrudan NaviagtionView'dan hemen önce çekmece düzeninde bulunur.Android - Koordinatör Düzeni, Çekmece Düzeni ve Fragmanlar

<?xml version="1.0" encoding="utf-8"?> 

<android.support.design.widget.CoordinatorLayout 
    android:id="@+id/main_content" 
    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" 
      android:background="?attr/colorPrimary" 
      app:layout_scrollFlags="scroll|enterAlways" 
      app:popupTheme="@style/ThemeOverlay.AppCompat.Light"/> 

     <android.support.design.widget.TabLayout 
      android:id="@+id/tabs" 
      android:layout_width="match_parent" 
      android:layout_height="wrap_content"/> 

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

    <android.support.v4.view.ViewPager 
     android:id="@+id/viewpager" 
     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="@dimen/fab_margin" 
     android:src="@drawable/ic_done"/> 

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

Bir FrameLayout (veya NestedScrollView) yerine ViewPager istiyorum:

<android.support.v4.widget.DrawerLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    xmlns:app="http://schemas.android.com/apk/res-auto" 
    android:id="@+id/drawer_layout" 
    android:layout_height="match_parent" 
    android:layout_width="match_parent" 
    android:fitsSystemWindows="true"> 

    <!-- THIS CONTAINS COORDINATOR LAYOUT with APPBAR LAYOUT + VIEWPAGER --> 
    <include layout="@layout/include_list_viewpager"/> 

    <android.support.design.widget.NavigationView 
     android:id="@+id/nav_view" 
     android:layout_height="match_parent" 
     android:layout_width="wrap_content" 
     android:layout_gravity="start" 
     android:fitsSystemWindows="true" 
     app:headerLayout="@layout/nav_header" 
     app:menu="@menu/drawer_view"/> 

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

include_list_viewpager dosyası budur. Daha sonra, kullanıcı, çekmece düzeni öğelerini tıklattıkça parçalara dinamik olarak yükleyebilir ve hepsinin hoş bir animasyonlu Araç Çubuğu olur. Şimdiye kadar, çağrılan fragmanlarda çalışırken Araç Çubuğunu kaydırmayı başaramıyorum. Hiç mümkün mü acaba?

Bunu hiç kimse başardı mı? Herhangi bir işaretçi büyük beğeni topluyor.

+0

bize bu kod çalışmıyor benim için cheesesquare app –

+0

include_list_viewpager düzeninizi göstermek, ben zaten eksik CoordinatorLayout etiketi ekledi, ama yine AppBarLayout içinde benim görünüm gerçekten orada duran, hiçbir şey yapıyoruz istikrarlı. herhangi bir fikir? – ticofab

cevap

6
<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:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar"> 

     <android.support.v7.widget.Toolbar 
      android:id="@+id/mToolbar" 
      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.TabLayout 
      android:id="@+id/tabLayout" 
      android:layout_width="match_parent" 
      android:layout_height="wrap_content"/> 

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

    <android.support.v4.widget.DrawerLayout 
     xmlns:android="http://schemas.android.com/apk/res/android" 
     xmlns:app="http://schemas.android.com/apk/res-auto" 
     android:id="@+id/drawer_layout" 
     android:layout_width="match_parent" 
     android:layout_height="match_parent" 
     android:fitsSystemWindows="true" 
     app:layout_behavior="@string/appbar_scrolling_view_behavior"> 

     <android.support.v4.view.ViewPager 
     android:id="@+id/tab_viewpager" 
     android:layout_width="match_parent" 
     android:layout_height="match_parent"/> 

     <android.support.design.widget.NavigationView 
     android:id="@+id/navigation_view" 
     android:layout_width="wrap_content" 
     android:layout_height="match_parent" 
     android:layout_gravity="start" 
     app:headerLayout="@layout/drawer_header" 
     app:menu="@menu/drawer"/> 
    </android.support.v4.widget.DrawerLayout> 

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

KoordinatörLayout tüm görünümlerin üst öğesi olmalıdır. DrawerLayout, layout_behavior değerini alır. Görüntüleyici unsurlarıyla etkileşime geçmek istediğinizden, DrawerLayout öğesinin üst görünümünde olması gerekir.

+0

gelen include_list_viewpager içeriğiyle düzenlenmiş – cV2