gpt4 book ai didi

android-viewpager - 带webView的NestedScrollView仅滚动NestedScrollView

转载 作者:行者123 更新时间:2023-12-04 04:09:42 25 4
gpt4 key购买 nike

下面是处理我的应用程序actionBar/toolbar/tabBar和nestedScrollView的正确行为的代码,其中包含ViewPager(webView)。 ViewPager基本上是一个普通的webView。

一切正常,但我的ViewPager无法垂直滚动。仅NestedScrollView正在滚动。我希望与Facebook应用程序具有相同的行为,如果滚动新闻源(webView),则tabBar会垂直将工具栏移出视觉范围。

<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>


因此,为了能够滚动viewPager(webView),我添加了一个扩展webView的新类:

public class TouchyWebView extends 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);
}
}


这解决了viewPager(webView)变为可滚动的问题。但是,NestedScrollView变为静态,并拒绝垂直滚动tabBar/toolbar。因此,我只能滚动webView或tabBar-toolbar。如何使viewPager(webView)和NestedScrollView(tabBar/toolbar)同时滚动?

我的web查看

<?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>


问候

最佳答案

这个对我有用,
将此行添加到XML文件中的NestedScrollview中。

 android:fillViewport="true"

然后
设置webview的高度wrap_content。
<WebView
android:id="@+id/webview"
android:layout_width="match_parent"
android:layout_height="wrap_content"/>

关于android-viewpager - 带webView的NestedScrollView仅滚动NestedScrollView,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47541793/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com