我想在 WebView 下方放置一个 Facebook Audience 网络横幅广告。我不希望广告与我的 WebView 重叠。我已经好几天没能实现了。
这是我的布局文件,我在约束布局中将广告放在 webview 之后
<?xml version="1.0" encoding="utf-8"?>
<android.support.constraint.ConstraintLayout 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:id="@+id/web_view_relative_layout"
android:layout_width="match_parent"
android:layout_height="match_parent"
app:layout_behavior="@string/appbar_scrolling_view_behavior"
tools:showIn="@layout/activity_main">
<View
android:id="@+id/divider"
android:layout_width="0dp"
android:layout_height="1dp"
android:background="?android:attr/listDivider"
app:layout_constraintTop_toTopOf="parent" />
<WebView
android:id="@+id/web_view_documentation"
android:layout_width="match_parent"
android:layout_height="wrap_content" />
<RelativeLayout
android:id="@+id/native_banner_ad_container"
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:layout_constraintBottom_toBottomOf="parent" />
</android.support.constraint.ConstraintLayout>
我在 webview 上方放置了一个 AppBarLayout。如果我添加约束,我的 webview 开始与应用栏重叠。
我的 webview 高度和宽度设置为 match_parent。我希望我的 WebView 占据广告后剩余的全部空间。所以,基本上,如果我的广告高度为 100dp,webview 应该填充剩余空间而不会重叠或欠重叠。提前致谢。
最佳答案
您可以将 View 置于垂直链中,这样当广告的 RelativeRelayout
容器的高度设置为 wrap_content 时,
:WebView
占据所有剩余空间
<?xml version="1.0" encoding="utf-8"?>
<android.support.constraint.ConstraintLayout 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:id="@+id/web_view_relative_layout"
android:layout_width="match_parent"
android:layout_height="match_parent"
app:layout_behavior="@string/appbar_scrolling_view_behavior"
tools:showIn="@layout/activity_main">
<View
android:id="@+id/divider"
android:layout_width="0dp"
android:layout_height="1dp"
android:background="?android:attr/listDivider"
app:layout_constraintBottom_toTopOf="@id/web_view_documentation"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"/>
<WebView
android:id="@+id/web_view_documentation"
android:layout_width="0dp"
android:layout_height="0dp"
app:layout_constraintBottom_toTopOf="@id/native_banner_ad_container"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@id/divider"/>
<RelativeLayout
android:id="@+id/native_banner_ad_container"
android:layout_width="0dp"
android:layout_height="wrap_content"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@id/web_view_documentation"/>
</android.support.constraint.ConstraintLayout>
关于android - 如何在 WebView 下方放置广告,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51458514/