【问题标题】:scrolling a webview inside a Listview won't work in android在 Listview 中滚动 webview 在 android 中不起作用
【发布时间】:2018-01-03 19:51:52
【问题描述】:

我有一个在 listView 中显示多个 webView 的应用程序。我的问题是当我尝试上下滚动 webView 时,webView 不响应我的手指,除非我只使用 3 个手指。当它响应时,它几乎不会上下移动。我发现问题在于 listview 禁止 webView 滚动。我试过使用:

listView.setEnabled(false);

但这对我不起作用。谁能告诉我如何解决这个问题? 这就是我在 listView 中添加 webView 布局的方式。

ArrayList<DefaultCards> cardsList = new ArrayList<>();
    cardsList.add(new DefaultCards("Hello Google","https://www.google.com", new WebViewClient()));
    CardsAdapter cardsAdapter = new CardsAdapter(this, cardsList);
    ListView listView = findViewById(R.id.cards_listview);
    listView.setAdapter(cardsAdapter);
    listView.setEnabled(false);

这是显示列表视图的布局:

<ListView
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/cards_listview"
android:layout_width="match_parent"
android:layout_height="match_parent"/>

最后,这是将被插入到 listView 中的布局:

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
xmlns:card_view="http://schemas.android.com/apk/res-auto"
android:background="@color/colorBackground"
android:padding="5dp">

<android.support.v7.widget.CardView
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    card_view:cardCornerRadius="4dp">

    <WebView
        android:id="@+id/webView"
        android:layout_width="match_parent"
        android:layout_height="300dp"
        android:layout_marginTop="50dp"/>


</android.support.v7.widget.CardView>

【问题讨论】:

    标签: android listview webview adapter


    【解决方案1】:

    对此持保留态度,但您可能想尝试为您的列表持有者使用回收器视图,为您的 webview 容器使用嵌套滚动视图。

    另外,如果 webview 的内容大到可以滚动,您可能需要在 webview 的 xml 中添加 isScrollContainer="true" 属性。

    同样,这只是一个疯狂的猜测。希望对您有所帮助!

    【讨论】:

    • 使用嵌套滚动视图对我有用。谢谢,帕蒂。
    • 很高兴它帮助了你!
    【解决方案2】:

    列表视图正在拦截滚动。您可以通过创建实现 NestedScrollingChild、NestedScrollingParent 的 NestedScrollingWebView 来防止这种情况发生。

    如果你搜索 Nested Scrolling Webview,会有很多代码示例。 使用它而不是常规的 Webview。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2022-10-26
      • 2018-05-08
      • 2022-01-05
      • 1970-01-01
      • 2016-02-26
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多