0

如何通過拖動滾動工具欄和TabLayout?在我的例子中,我有這樣的main.xmlAndroid - 工具欄和TabLayout滾動如果向上/向下拖動它們

<android.support.design.widget.CoordinatorLayout 
    android:id="@+id/main_layout" 
    xmlns:android="http://schemas.android.com/apk/res/android" 
    xmlns:app="http://schemas.android.com/apk/res-auto" 
    xmlns:ads="http://schemas.android.com/apk/res-auto" 
    xmlns:tools="http://schemas.android.com/tools" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    tools:context=".MainActivity"> 

    <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" 
     android:fitsSystemWindows="true"> 

     <android.support.v7.widget.Toolbar 
      android:id="@+id/toolbarMain" 
      android:layout_width="match_parent" 
      android:layout_height="wrap_content" 
      android:layout_alignParentTop="true" 
      android:background="?attr/colorPrimary" 
      android:elevation="1dp" 
      android:minHeight="?attr/actionBarSize" 
      android:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar" 
      app:popupTheme="@style/ThemeOverlay.AppCompat.Light" 
      app:layout_scrollFlags="scroll|enterAlways|snap"/> 

     <android.support.design.widget.TabLayout 
      android:id="@+id/tab_layout" 
      android:layout_width="match_parent" 
      android:layout_height="wrap_content" 
      android:layout_below="@+id/toolbar" 
      android:background="?attr/colorPrimary" 
      app:layout_scrollFlags="scroll|enterAlways" 
      android:minHeight="?attr/actionBarSize" 
      android:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar"/> 
     </android.support.design.widget.AppBarLayout> 

    <android.support.v4.view.ViewPager 
     android:id="@+id/pager" 
     android:layout_width="match_parent" 
     android:layout_height="fill_parent" 
     android:layout_below="@id/tab_layout" 
     app:layout_behavior="@string/appbar_scrolling_view_behavior" /> 
</android.support.design.widget.CoordinatorLayout> 

ViewPager包含recycleview的片段。問題是,即使沒有實例化recycleview,我也可以上下拖動工具欄和TabLayout。我希望該工具欄和TabLayout只在滾動recycleview時滾動。你有什麼想法如何實現它?

回答

0

在您的活動類,你可以把:

tabLayout.setClickable(false); 

tabLayout.setEnabled(false); 

而且只啓用再次所需的條件。

+0

我設置它,但工具欄和TabLayout仍然滾動。任何其他想法? – athene

相關問題