【发布时间】:2020-01-20 11:38:36
【问题描述】:
我想在 webview 的滚动末尾添加一个自定义视图,所以当用户到达 webview 的末尾时,他可以看到自定义视图。 如何在 Android 中实现这一目标?
<ScrollView
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1"
android:fillViewport="true">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<WebView
android:id="@+id/webView"
android:layout_width="match_parent"
android:layout_height="wrap_content"/>
<com.app.util.CustomView
android:visibility="visible"
android:layout_width="match_parent"
android:layout_height="wrap_content" />
</LinearLayout>
</ScrollView>
我尝试将自定义视图放在底部和滚动视图内,但效果不佳,webview 和我的自定义视图之间有很大的空白区域
编辑
我尝试了嵌套滚动但仍然无法正常工作,对于这个网址“https://vimeo.com/171614342#embed”,它看起来像这样
<?xml version="1.0" encoding="utf-8"?>
<androidx.core.widget.NestedScrollView 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"
android:layout_width="match_parent"
android:layout_height="match_parent">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<WebView
android:id="@+id/webView"
android:layout_width="match_parent"
android:layout_height="wrap_content" />
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:textColor="@android:color/white"
android:padding="10dp"
android:background="@android:color/holo_red_dark"
android:text="Hello World!" />
</LinearLayout>
</androidx.core.widget.NestedScrollView>
【问题讨论】:
-
如果你添加任何你尝试过的相关sn-ps就可以了。它可能会帮助 stackoverflow 用户解决您的问题
-
在下面查看我的答案
-
拥有滚动视图的父布局是什么?
-
NestedScrollView 是父级,它是片段的布局,包含这个片段的活动有 FrameLayout 持有片段
-
顶部的工具栏怎么来的?可能您需要将活动扩展到 AppCompatActivity
标签: android android-studio webview android-webview