2016-05-25 53 views
1

在具有ViewPager和三个片段的活动中,我想自动隐藏ToolBar。为此,我正在使用android.support.design.widget.CoordinatorLayout工具栏重叠坐标布局下的活动

ViewPager给我一些问题。如果它在CoordinateLayout中,ToolBar与活动重叠。如果它在CoordinatorLayout之外,则ToolBar活动不会与WebView活动重叠。如果ViewPagerCoordinatorLayout之外,自动隐藏不起作用。

任何帮助,将不胜感激。

activity_main.xml中

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    xmlns:tools="http://schemas.android.com/tools" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    android:orientation="vertical" 
    tools:context=".MainActivity"> 

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

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

      <android.support.v7.widget.Toolbar 
       android:id="@+id/tool_bar" 
       xmlns:android="http://schemas.android.com/apk/res/android" 
       android:layout_height="wrap_content" 
       android:layout_width="match_parent" 
       xmlns:app="http://schemas.android.com/apk/res-auto" 
       android:background="@color/ColorPrimary" 
       android:elevation="2dp" 
       android:theme="@style/Base.ThemeOverlay.AppCompat.Dark" 
       android:popupTheme="@style/ThemeOverlay.AppCompat.Light" 
       app:layout_scrollFlags="scroll|enterAlways" 
       android:fitsSystemWindows="true" /> 

      <com.taadu.slidechat.adaptor.SlidingTabLayout 
       android:id="@+id/tabs" 
       android:layout_width="match_parent" 
       android:layout_height="wrap_content" 
       android:background="@color/ColorPrimary"/> 

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

     <android.support.v4.view.ViewPager 
      xmlns:android="http://schemas.android.com/apk/res/android" 
      android:id="@+id/pager" 
      android:layout_width="match_parent" 
      android:layout_height="match_parent"> 
     </android.support.v4.view.ViewPager> 
    </android.support.design.widget.CoordinatorLayout> 

</LinearLayout> 

我一直在尝试用线性布局,如果ViewPagerLinearLayout活动并不重叠,但是这消除了自动隐藏功能。

我已经添加了android.support.v4.widget.NestedScrollView只有一个片段来测试自动隐藏。请看一看。

<android.support.v4.widget.NestedScrollView 
    xmlns:android="http://schemas.android.com/apk/res/android" 
    xmlns:app="http://schemas.android.com/apk/res-auto" 
    android:isScrollContainer="false" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    android:layout_gravity="fill_vertical" 
    android:clipToPadding="false" 
    app:layout_behavior="@string/appbar_scrolling_view_behavior"> 


    <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" 
     xmlns:ads="http://schemas.android.com/apk/res-auto" 
     android:layout_width="match_parent" 
     android:layout_height="match_parent" 
     android:orientation="vertical" 
     app:layout_behavior="@string/appbar_scrolling_view_behavior"> 

     <ProgressBar 
      android:id="@+id/progressBar3" 
      style="?android:attr/progressBarStyleHorizontal" 
      android:layout_width="fill_parent" 
      android:layout_height="3dip" 
      android:max="100" 
      android:progressDrawable="@drawable/greenprogress" /> 

     <WebView xmlns:android="http://schemas.android.com/apk/res/android" 
      android:id="@+id/webViewTop" 
      android:layout_width="fill_parent" 
      android:layout_height="fill_parent" 
      android:layout_below="@id/progressBar3"/> 
    </RelativeLayout> 

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

回答

4

,这是因为你是给layout_behaviorNestedScrollView而不是你的ViewPager

添加app:layout_behavior="@string/appbar_scrolling_view_behavior"ViewPage

ViewPager应该像

<android.support.v4.view.ViewPager 
    xmlns:android="http://schemas.android.com/apk/res/android" 
    android:id="@+id/pager" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    app:layout_behavior="@string/appbar_scrolling_view_behavior> 
</android.support.v4.view.ViewPager> 
+0

谢谢!那就做到了! – Mustansir

+0

你可以接受答案.. –

+0

在2分钟内:)...... – Mustansir

相关问题