代码之家  ›  专栏  ›  技术社区  ›  AbdulRhman

在Listview中滚动Web视图在android中不起作用

  •  0
  • AbdulRhman  · 技术社区  · 7 年前

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

    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的布局:

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

    2 回复  |  直到 7 年前
        1
  •  0
  •   Patty P    7 年前

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

    此外,如果webview的内容足够大,可以滚动,则可能需要将isScrollContainer=“true”属性添加到webview的xml中。

    同样,这只是一个猜测。希望有帮助!

        2
  •  0
  •   Mustafa Dualeh    7 年前

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

    如果搜索嵌套滚动Webview,则有许多代码示例。 使用它而不是常规的Web视图。