2017-02-10 89 views
0

我試圖自動隱藏和顯示取決於在ViewPager中實現的TextView的滾動。但是,工具欄從不隱藏滾動。 主要XML activity_data_display.xml工具欄不隱藏/顯示在滾動協調器佈局

<android.support.v4.widget.DrawerLayout 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_drawer" 
android:layout_width="match_parent" 
android:layout_height="match_parent" 
tools:context="com.regio.developers.upasana.DataDisplayActivity"> 

<android.support.design.widget.CoordinatorLayout 
    android:id="@+id/activity_data_display" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    android:background="@drawable/bg"> 

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

     <include 
      android:id="@+id/toolbar" 
      layout="@layout/toolbar_layout" 
      android:layout_width="match_parent" 
      android:layout_height="wrap_content" /> 

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

    <android.support.v4.view.ViewPager 
     android:id="@+id/data_viewpager" 
     android:layout_width="match_parent" 
     android:layout_height="match_parent" 
     app:layout_behavior="@string/appbar_scrolling_view_behavior"/> 

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

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

下面是在ViewPager充氣佈局 data_swipe_layout.xml

<android.support.v4.widget.NestedScrollView 
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="wrap_content" 
app:layout_behavior="@string/appbar_scrolling_view_behavior"> 

    <TextView 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:id="@+id/dataviewpager_textview" 
     android:textColor="#FFF" 
     android:paddingTop="20dp" 
     android:paddingBottom="20dp" 
     android:paddingRight="35dp" 
     android:paddingLeft="35dp" 
     android:textSize="20sp" 
     android:gravity="center"/> 

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

添加 工具欄版式文件 toolbar_layout.xml

<?xml version="1.0" encoding="utf-8"?> 
<android.support.v7.widget.Toolbar 
xmlns:android="http://schemas.android.com/apk/res/android" 
xmlns:app="http://schemas.android.com/apk/res-auto" 
android:id="@+id/toolbar" 
android:layout_width="match_parent" 
android:layout_height="wrap_content" 
android:background="?attr/colorPrimary" 
android:fitsSystemWindows="true" 
android:minHeight="?attr/actionBarSize" 
app:theme="@style/ToolBarStyle" 
app:layout_scrollFlags="scroll|enterAlways" 
> 

</android.support.v7.widget.Toolbar> 

請解決我的問題?

我已經嘗試了不同的方式來使它像在主XML文件中使用NestedScrollView一樣工作。但是,這並沒有幫助。

請嘗試實施自己,然後給我這個解決方案。

記得我已經使用了包含數百行文本的TextView。

另外,如何實現ScrollBar,它可以在ViewPager中爲TextView手動拖動?

+0

在工具欄上,你必須使用的應用程序:layout_scrollFlags.check此[鏈接](http://guides.codepath.com/android/handling-scrolls-with-coordinatorlayout) –

+0

我使用的應用程序: layout_scrollFlags =「scroll | enterAlways」在toolbar_layout文件中 –

回答

2

您使用工具欄的佈局包括你應該做這個屬性的應用程序:layout_scrollFlags =「滾動| enterAlways」

爲AppBarLayout或寫工具欄的AppBarLayout代碼。

希望這會有所幫助。

+1

感謝它的工作。你也可以告訴我如何顯示滾動條? –

+0

如果您有解決方案標記,我的解決方案已驗證 –

+0

將它全部放入或者您可以將佈局的屬性設置爲可滾動。希望適用於你的情況 –

1
Check this. 
it is working 
<android.support.v4.widget.DrawerLayout 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_drawer" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent"> 

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

    <android.support.design.widget.AppBarLayout 
     android:id="@+id/appbar" 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:fitsSystemWindows="true"> 

     <android.support.v7.widget.Toolbar 
      android:id="@+id/toolbarsdfs" 
      android:layout_width="match_parent" 
      android:layout_height="?attr/actionBarSize" 
      android:background="?attr/colorPrimary" 
      app:layout_scrollFlags="scroll|enterAlways"/> 
    </android.support.design.widget.AppBarLayout> 

    <android.support.v4.widget.NestedScrollView 
     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="wrap_content" 
     app:layout_behavior="@string/appbar_scrolling_view_behavior"> 

     <TextView 
      android:layout_width="match_parent" 
      android:layout_height="wrap_content" 
      android:id="@+id/dataviewpager_textview" 
      android:textColor="#FFF" 
      android:paddingTop="20dp" 
      android:paddingBottom="20dp" 
      android:paddingRight="35dp" 
      android:paddingLeft="35dp" 
      android:textSize="20sp" 
      android:text="" 
      android:gravity="center"/> 

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

</android.support.design.widget.CoordinatorLayout> 
</android.support.v4.widget.DrawerLayout> 
相關問題