Dưới đây là mã của tôi để xử lý hành vi chính xác của các ứng dụng của tôi actionBar/toolbar/tabBar và nestedScrollView với một ViewPager (webView) bên trong nó. ViewPager về cơ bản là một webView bình thường.NestedScrollView với webView chỉ cuộn NestedScrollView
Mọi thứ hoạt động tốt ngoại trừ ViewPager của tôi không thể cuộn theo chiều dọc. Chỉ có NestedScrollView đang được cuộn. Tôi muốn có hành vi tương tự như ứng dụng Facebook, nếu bạn cuộn nguồn cấp tin tức (webView), thanh tabBar sẽ di chuyển thanh công cụ ra khỏi tầm nhìn theo chiều dọc.
<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" tools:context=".ui.activity.FragmentContainer" android:layout_width="match_parent" android:layout_height="match_parent" android:orientation="vertical" > <android.support.design.widget.AppBarLayout android:layout_width="match_parent" android:layout_height="wrap_content" > <android.support.v7.widget.Toolbar android:id="@+id/toolbar" app:theme="@style/M.Toolbar" app:popupTheme="@style/M.Toolbar.PopupTheme" android:layout_width="match_parent" android:layout_height="?attr/actionBarSize" app:layout_scrollFlags="scroll|enterAlways" > </android.support.v7.widget.Toolbar> <android.support.design.widget.TabLayout android:id="@+id/tabs" android:layout_width="match_parent" android:layout_height="wrap_content" app:tabMode="scrollable" android:visibility="gone" android:background="@color/background" app:background="@color/background" /> </android.support.design.widget.AppBarLayout> <android.support.v4.widget.NestedScrollView android:layout_height="match_parent" android:layout_width="match_parent" app:layout_behavior="@string/appbar_scrolling_view_behavior" android:background="@android:color/transparent" android:fillViewport="true" > <com.m.ui.util.EdgeScrollViewPager android:id="@+id/viewpager" android:layout_width="match_parent" android:layout_height="match_parent" android:background="@android:color/transparent" android:visibility="visible" > </com.m.ui.util.EdgeScrollViewPager> </android.support.v4.widget.NestedScrollView> </android.support.design.widget.CoordinatorLayout>
Vì vậy, để có thể di chuyển ViewPager tôi (WebView) Tôi đã thêm một lớp mới mà mở rộng WebView:
public class TouchyWebView kéo dài WebView {
public TouchyWebView(Context context) { super(context); } public TouchyWebView(Context context, AttributeSet attrs) { super(context, attrs); } public TouchyWebView(Context context, AttributeSet attrs, int defStyle) { super(context, attrs, defStyle); } @Override public boolean onTouchEvent(MotionEvent event){ requestDisallowInterceptTouchEvent(true); return super.onTouchEvent(event); } }
Điều này s olves vấn đề với viewPager (webView) mà có thể cuộn được. NHƯNG, NestedScrollView trở nên tĩnh và từ chối di chuyển thanh tabBar/thanh công cụ theo chiều dọc. Vì vậy, tôi đang mắc kẹt bằng cách di chuyển webView HOẶC thanh công cụ tabBar. Làm thế nào để tôi có thể cuộn cả hai viewPager (webView) và NestedScrollView (tabBar/toolbar) cùng một lúc?
WebView My
<?xml version="1.0" encoding="utf-8"?> <FrameLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent" android:layout_height="match_parent" android:background="@android:color/white"> <com.m.ui.base.TouchyWebView android:id="@+id/web_webview" android:layout_width="match_parent" android:layout_height="match_parent" android:background="@android:color/transparent" android:visibility="visible" /> <LinearLayout android:id="@+id/web_loadingview" android:orientation="vertical" android:layout_width="wrap_content" android:layout_height="wrap_content" android:visibility="gone" android:layout_gravity="center"> <ProgressBar style="?android:attr/progressBarStyleLarge" android:layout_width="wrap_content" android:layout_height="wrap_content" android:indeterminate="true" android:visibility="visible" android:layout_gravity="center"/> </LinearLayout> </FrameLayout>
Trân