NestedScrollView中的WebView无法滚动 [英] WebView inside NestedScrollView cannot be scrolled

查看:1438
本文介绍了NestedScrollView中的WebView无法滚动的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个使用WebView加载网页内容的活动.当我想用图像实现灵活空间时会出现问题.我可以展开和折叠Toolbar,但是当Toolbar已经折叠时,滚动条将卡在其中.我无法滚动WebView中的内容.

I've got an activity that use WebView to load the web content. The problem arise when I want to implement Flexible Space with image. I can expand and collapse the Toolbar, but when the Toolbar already collapsed, The scrollbar stuck there. I can't scroll the content inside the WebView.

这是XML:

<android.support.v4.widget.NestedScrollView
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:clipToPadding="false"
    android:fillViewport="true"
    app:layout_behavior="@string/appbar_scrolling_view_behavior">

    <WebView
        android:id="@+id/read_full_content_wv"
        android:layout_width="match_parent"
        android:layout_height="match_parent"/>


</android.support.v4.widget.NestedScrollView>

您对此有任何解决方案吗?

Do you have any solution for this?

关于, 埃尔默

编辑 之后,我看一下LinX64给出的链接.我尝试添加:

EDIT After I look at the link that given by LinX64. I tried to add:

public class FullContentActivity extends AppCompatActivity {
   ...
   @Override
   protected void onCreate(Bundle savedInstance){
      ...
      WebView webView = (WebView) findViewById(R.id.read_full_content_wv);
      webView.setWebViewClient(new MyBrowser());
      webView.loadData(extra.get(1).toString(), "text/html", "utf-8");
      ...
   }
   ...
   private class MyBrowser extends WebViewClient {
      @Override
      public void onPageStarted(WebView view, String url, Bitmap favicon){
         NestedScrollView nsv = (NestedScrollView) findViewById(R.id.nsv_fc);
         nsv.scrollTo(0,0);
      }
   }
}

仍然卡住了.

编辑2 仅供参考:我尝试使用ASUS Zenfone 6-KitKat 4.4.2 KitKat可能无法正确加载吗?

EDIT 2 FYI: I tried on ASUS Zenfone 6 - KitKat 4.4.2 Is it possible KitKat can't load it correctly?

针对该问题的最佳解决方案

解决后,我认为我无法使用CollapsingToolbarLayout与WebView结合使用Flex Space的经验,因此我将WebView更改为TextView并使用Html.fromHtml()来读取内容.除非Google要更新或修复某些功能,否则我们可以将CollapsingToolbarLayout和WebView结合在一起.

After working around, I think I cannot get experience I want for Flexible Space using CollapsingToolbarLayout combined with WebView, so I changed WebView to TextView and use Html.fromHtml() to read the content. Unless Google gonna update or fix some features so we can combine CollapsingToolbarLayout and WebView together.

推荐答案

通过更改基础Webview的height属性来解决这一问题.

Got this one working with changing the height attribute of the underlying Webview.

对于NestedScrollView使用属性

For NestedScrollView use attribute

android:fillViewport="true"

,对于WebView,请使用android:layout_height="wrap_content"

and for WebView use android:layout_height="wrap_content"

完整答案此处

这篇关于NestedScrollView中的WebView无法滚动的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆