我有以下XML:
<android.support.design.widget.CoordinatorLayout
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:layout_width="match_parent"
android:layout_height="match_parent" android:fitsSystemWindows="true"
tools:context="socialcenterapp.com.user.myapp.activities.MainActivity">
<android.support.design.widget.AppBarLayout android:layout_height="wrap_content"
android:layout_width="match_parent" android:theme="@style/AppTheme.AppBarOverlay"
android:id="@+id/appBarLayout">
<android.support.v7.widget.Toolbar android:id="@+id/toolbar"
android:titleTextColor="#FFFFFF"
android:layout_width="match_parent" android:layout_height="?attr/actionBarSize"
android:background="@drawable/side_nav_bar" app:popupTheme="@style/AppTheme.PopupOverlay">
<android.support.design.widget.FloatingActionButton android:id="@+id/fab"
android:layout_width="24dp" android:layout_height="24dp"
android:scaleType="center"
android:layout_gravity="bottom|right" android:layout_margin="30dp"
android:src="@mipmap/icon_fab"
app:backgroundTint="#b3c8ff"
app:layout_scrollFlags="scroll|enterAlways"
/>
</android.support.v7.widget.Toolbar>
<android.support.design.widget.CollapsingToolbarLayout
android:id="@+id/collapse_toolbar"
android:layout_width="match_parent"
android:layout_height="match_parent"
app:layout_scrollFlags="scroll|exitUntilCollapsed"
android:background="@color/material_deep_teal_500"
android:fitsSystemWindows="true">
<android.support.design.widget.TabLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="@drawable/side_nav_bar"
android:id="@+id/tabLayout"
app:layout_scrollFlags="scroll|enterAlways"/>
</android.support.design.widget.CollapsingToolbarLayout>
</android.support.design.widget.AppBarLayout>
<android.support.v4.view.ViewPager
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/viewPager"
android:layout_alignParentTop="true"
android:layout_alignParentRight="true"
android:layout_alignParentEnd="true"
app:layout_behavior="@string/appbar_scrolling_view_behavior"
/>
</android.support.design.widget.CoordinatorLayout>
在ViewPager中我有包含WebView的Fragment。
我希望当用户在WebView中向下滚动时TabLayout消失并向上滚动。
我该怎么做?
片段XML:
<FrameLayout 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"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:orientation="vertical"
tools:context="myapp.com.user.myapp.fragments.MyFragment">
<WebView>
<android:layout_width="match_parent">
<android:layout_height="match_parent">
<android:id="@+id/webView">
<android:layout_gravity="left|top" />
</FrameLayout>
答案 0 :(得分:2)
<android.support.v4.widget.NestedScrollView
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
>
<WebView
android:id="@+id/webView"
android:layout_width="match_parent"
android:layout_height="match_parent"
/>