gpt4 book ai didi

java - Webview + 底部的 admob + LinearLayout

转载 作者:行者123 更新时间:2023-12-01 23:12:59 26 4
gpt4 key购买 nike

我无法使用 LinearLayout 中的 Web View (顶部有进度条)在底部正确发布 admob。我尝试了很多方法,使用亲戚,在 Stackoverflow 中搜索并按照一些步骤操作,但这个进度条不起作用。

    <?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:ads="http://schemas.android.com/apk/lib/com.google.ads"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical" >

<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="vertical" >

<ProgressBar
android:id="@+id/ProgressBar"
style="?android:attr/progressBarStyleHorizontal"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:indeterminate="false"
android:maxHeight="10dip"
android:minHeight="10dip"
android:progress="50"
android:progressDrawable="@drawable/greenprogress" />

<WebView
android:id="@+id/webview"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1" />
</LinearLayout>

<com.google.ads.AdView
android:id="@+id/adView"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1"
ads:adSize="BANNER"
ads:adUnitId="ca-app-pub-7041222655570180/1503313077"
ads:loadAdOnCreate="true"
ads:refreshInterval="30" >
</com.google.ads.AdView>

</LinearLayout>

最佳答案

您发布的布局将不起作用,因为您的内部线性布局的高度为 wrap_content(从而导致其子级的 layout_weight 被忽略),但 Web View 具有高度为 0。您还将广告 View 的权重设置为 1,就好像它应该占据尽可能多的空间,而通常广告应该具有固定的高度。

我不确定为什么RelativeLayout不适合你,但也许你试图将它与layout_weight一起使用?如果是这样,请注意 layout_weight 仅适用于 LinearLayout 的子级。

这是我的做法:

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:ads="http://schemas.android.com/apk/lib/com.google.ads"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >

<com.google.ads.AdView
android:id="@+id/adView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_alignParentTop="false"
android:layout_centerHorizontal="true"
ads:adSize="BANNER"
ads:adUnitId="ca-app-pub-7041222655570180/1503313077"
ads:loadAdOnCreate="true"
ads:refreshInterval="30" >
</com.google.ads.AdView>

<LinearLayout
android:layout_alignParentTop="true"
android:layout_above="@id/adView"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >

<ProgressBar
android:id="@+id/ProgressBar"
style="?android:attr/progressBarStyleHorizontal"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
android:indeterminate="false"
android:progress="50"
android:progressDrawable="@drawable/greenprogress" />

<WebView
android:id="@+id/webview"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1" />
</LinearLayout>


</RelativeLayout>

关于java - Webview + 底部的 admob + LinearLayout,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21583875/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com