在具有ViewPager
和三个片段的活动中,我想自动隐藏ToolBar
。为此,我正在使用android.support.design.widget.CoordinatorLayout
。工具栏重叠坐标布局下的活动
但ViewPager
给我一些问题。如果它在CoordinateLayout
中,ToolBar
与活动重叠。如果它在CoordinatorLayout
之外,则ToolBar
活动不会与WebView
活动重叠。如果ViewPager
在CoordinatorLayout
之外,自动隐藏不起作用。
任何帮助,将不胜感激。
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>
我一直在尝试用线性布局,如果ViewPager
是LinearLayout
活动并不重叠,但是这消除了自动隐藏功能。
我已经添加了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>
谢谢!那就做到了! – Mustansir
你可以接受答案.. –
在2分钟内:)...... – Mustansir