android - Nestedscrollview/Scrollview 中的 Webview 缺少内容
问题描述
我有一个放置在嵌套滚动视图中的 web 视图。我面临的问题是 webview 没有加载整页。相反,它会加载页面的一部分,然后将底部空间保持为空白(白色)。
我也尝试过使用滚动视图。
我得到的输出:
我的 webview 代码:
private ImageButton backButton;
private WebView webView;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_article);
backButton = findViewById(R.id.backButton);
webView=(WebView)findViewById(R.id.webView);
webView.setWebViewClient(new MyBrowser());
// if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) {
// descriptionView.setText(Html.fromHtml(data, Html.FROM_HTML_MODE_COMPACT));
// } else {
// descriptionView.setText(Html.fromHtml(data));
// }
webView.getSettings().setJavaScriptEnabled(true);
webView.loadUrl("file:///android_asset/html/test.html");
backButton.setOnClickListener(this);
}
private class MyBrowser extends WebViewClient {
@Override
public boolean shouldOverrideUrlLoading(WebView view, String url) {
view.loadUrl(url);
return true;
}
}
布局文件:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:card_view="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".Activities.ArticleActivity">
<RelativeLayout
android:id="@+id/topBar"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="@color/colorPrimary">
<ImageButton
android:id="@+id/backButton"
android:layout_width="48dp"
android:layout_height="48dp"
android:layout_centerVertical="true"
android:layout_marginLeft="10dp"
android:background="@null"
card_view:srcCompat="@drawable/outline_arrow_back_ios_24" />
<ImageView
android:layout_width="wrap_content"
android:layout_height="20dp"
android:layout_centerInParent="true"
android:layout_margin="20dp"
android:scaleType="centerInside"
android:src="@drawable/x01" />
</RelativeLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_below="@+id/topBar">
<ScrollView
android:layout_width="match_parent"
android:layout_height="match_parent">
<android.support.v7.widget.CardView
android:id="@+id/card_view"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_margin="10dp"
card_view:cardCornerRadius="2dp">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_gravity="center"
android:orientation="vertical">
<ImageView
android:id="@+id/iconView"
android:layout_width="match_parent"
android:layout_height="120dp"
android:layout_centerVertical="true"
android:scaleType="centerCrop"
android:src="@drawable/article" />
<com.virtual_antivirus.virtualantivirus.Utlis.BanglaTextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginBottom="10dp"
android:layout_marginLeft="10dp"
android:layout_marginRight="10dp"
android:layout_marginTop="10dp"
android:text="ভার্চুয়াল ভাইরাসের সর্বনাশা শিকার"
android:textColor="@android:color/black"
android:textSize="18sp"
android:textStyle="bold" />
<LinearLayout
android:layout_width="100dp"
android:layout_height="5dp"
android:layout_marginLeft="10dp"
android:background="@color/colorAccent"></LinearLayout>
<FrameLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:minHeight="300dp">
<WebView
android:id="@+id/webView"
android:layout_width="match_parent"
android:layout_height="match_parent" />
</FrameLayout>
</LinearLayout>
</android.support.v7.widget.CardView>
</ScrollView>
</LinearLayout>
<View
android:layout_width="match_parent"
android:layout_height="5dp"
android:layout_below="@+id/topBar"
android:background="@drawable/shadow" />
</RelativeLayout>
解决方案
您可以将 NestedScrollView 放置在 Coordinator 布局中,如果您使用的是应用栏,则必须禁用滚动行为并放置布局行为。
<android.support.v4.widget.NestedScrollView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fillViewport="true"
android:nestedScrollingEnabled="false"
app:layout_behavior="appbar_scrolling_view_behavior">
.....
推荐阅读
- python - BeautfilSoup Python,获取两个标签之间的所有文本
- c++ - 打开与 Qt/C++ 的数据库连接
- python-3.x - python 的 pandas.DataFrame 函数有什么替代方法吗?
- ios - 如何从方形阅读器 sdk 中删除结果弹出窗口
- ruby-on-rails - Rails High_Voltage 错误:#<# 的未定义方法“page_path”
- flutter - 如何将 Flutter 应用中的帖子分享到 inkedIn、facebook 等社交媒体平台?
- ruby-on-rails - 如何摆脱让使用之前
- python - 我在我的像素本上安装了 Anaconda3,但 Spyder 无法工作...ImportError: libGL.so.1: cannot open shared object file: No such file or directory
- python - 如何查看 Hypothesis Python 库的“Bundle”输出?(有状态测试)
- timeout - HAProxy 2.0.6-1~bpo9+1 服务器健康检查失败,原因:第四层超时