2017-06-22 48 views
-1

在我的佈局,我有CoordinatorLayout與垂直方向的父母, 1 - 工具欄 2 - 中的LinearLayout 內容3 - TabLayout 4 - ViewPager如何滾動工具欄和標籤佈局之間的內容

當我向上滾動內容應該與查看尋呼機一起滾動,標籤佈局應該附帶工具欄。

怎麼辦?

<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/coordinatorLayout" 
     android:layout_width="fill_parent" 
     android:layout_height="fill_parent"> 

     <!-- AppBar Layout --> 
     <android.support.design.widget.AppBarLayout 
      android:id="@+id/appBarLayout" 
      android:layout_width="fill_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="fill_parent" 
       android:layout_height="?attr/actionBarSize" 
       android:isScrollContainer="true" 
       android:background="?attr/colorPrimary" 
       app:popupTheme="@style/ThemeOverlay.AppCompat.Light" /> 

      <RelativeLayout 
       app:layout_scrollFlags="scroll|enterAlways" 

       android:layout_width="match_parent" 
       android:layout_height="wrap_content"> 

       <ImageView 
        android:layout_centerInParent="true" 
        android:src="@mipmap/ic_launcher" 
        android:layout_width="wrap_content" 
        android:layout_height="wrap_content" /> 

      </RelativeLayout> 
      <!-- Tab Layout for creating tabs --> 
      <android.support.design.widget.TabLayout 
       android:id="@+id/tabLayout" 
       android:layout_width="fill_parent" 
       android:layout_height="wrap_content" /> 
     </android.support.design.widget.AppBarLayout> 
     <!-- Helps handing the Fragments for each Tab --> 
     <android.support.v4.view.ViewPager 
      android:id="@+id/viewPager" 
      android:layout_width="fill_parent" 
      android:layout_height="fill_parent" 
      app:layout_behavior="@string/appbar_scrolling_view_behavior" /> 
    </android.support.design.widget.CoordinatorLayout> 

回答

0

你需要用一個NestedScrollViewViewPager和移動佈局行爲滾動視圖。

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

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

      <android.support.v4.view.ViewPager 
       android:id="@+id/viewPager" 
       android:layout_width="match_parent" 
       android:layout_height="match_parent" /> 
     </android.support.v4.widget.NestedScrollView 
+0

如何滾動只工具欄和標籤佈局之間的內容? –

0

//佈局

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

<RelativeLayout android:layout_height="match_parent" 
    android:layout_width="match_parent" 
    xmlns:android="http://schemas.android.com/apk/res/android" 
    xmlns:app="http://schemas.android.com/apk/res-auto"> 

    <include 
     android:id="@+id/user_toolbar" 
     layout="@layout/toolbar_user_profile"/> 


    <android.support.design.widget.CoordinatorLayout 
     android:layout_below="@id/user_toolbar" 
     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:orientation="vertical"> 



     <android.support.design.widget.AppBarLayout 
      android:layout_width="match_parent" 
      android:layout_height="wrap_content" 
      android:background="@color/white" 
      android:fitsSystemWindows="true" 
      android:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar"> 


      <android.support.design.widget.CollapsingToolbarLayout 
       android:id="@+id/collapse_toolbar" 
       android:layout_width="match_parent" 
       android:layout_height="wrap_content" 
       android:fitsSystemWindows="true" 
       app:contentScrim="@color/white" 
       app:layout_scrollFlags="scroll|exitUntilCollapsed|snap" 
       app:scrimAnimationDuration="100" 
       app:titleEnabled="false"> 

       <LinearLayout 
        android:layout_width="match_parent" 
        android:layout_height="wrap_content" 
        android:fitsSystemWindows="true" 
        android:scaleType="centerCrop" 
        > 
        <include layout="@layout/user_content_profile_screen" /> 
       </LinearLayout> 


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

      <android.support.design.widget.TabLayout 
       android:id="@+id/tabs" 
       android:layout_gravity="bottom" 
       android:layout_width="match_parent" 
       android:layout_height="wrap_content" 
       android:background="@color/white" 
       android:visibility="visible" 
       app:layout_collapseMode="pin" 
       app:tabIndicatorColor="@color/black" 
       app:tabSelectedTextColor="@color/black" 
       app:tabTextColor="@color/levelTextColor" 

       /> 

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

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

      <android.support.v4.view.ViewPager 
       android:id="@+id/pager" 
       android:layout_width="match_parent" 
       android:layout_height="match_parent" 
       android:background="@color/white" /> 

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


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

    <android.support.design.widget.FloatingActionButton 
     android:id="@+id/add_subjects" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:layout_alignParentBottom="true" 
     android:layout_alignParentRight="true" 
     android:layout_margin="16dp" 
     android:src="@drawable/ic_add_white_24dp" 
     android:visibility="gone" 
     app:backgroundTint="@color/levelBackground" 
     app:borderWidth="0dp" 
     app:fabSize="normal" 
     app:layout_anchor="@+id/viewPager" 
     app:layout_anchorGravity="bottom|right|end" 
     app:layout_behavior="com.example.simon.behaviours.ScrollingFABBehavior" /> 


</RelativeLayout> 
相關問題