【问题标题】:How to ad Placement with webview at the bottom properly?如何正确地在底部使用 webview 广告展示位置?
【发布时间】:2021-08-16 09:38:41
【问题描述】:

我想把广告放在这个 WebView 的末尾..

但是当我将它放在 WebView 下时,它不显示。如果我把它放在 WebView 上方,我会像附件一样显示......

我尝试改变宽度和高度,但它也不起作用!这就是为什么我的 Facebook 观众向我显示你的广告位置错误的警告.. 我该如何解决?

<androidx.constraintlayout.widget.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:layout_width="match_parent"
    android:layout_height="match_parent"
    tools:context=".Policy.PrivacyPolicy">


    <LinearLayout


        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:gravity="center"
        android:orientation="vertical">

        <androidx.appcompat.widget.Toolbar
            android:id="@+id/toolbar"
            android:layout_width="match_parent"
            android:layout_height="?attr/actionBarSize"
            android:background="#E53935"
            android:textAlignment="center"
            app:popupTheme="@style/Theme.BangabandhuT20Cup.PopupOverlay"
            app:title="@string/privacy_policy_title"
            app:titleTextColor="#FFFFFF">
        </androidx.appcompat.widget.Toolbar>

       


        <WebView
            android:id="@+id/policyWebView"
            android:layout_width="fill_parent"
            android:layout_height="fill_parent">
        </WebView>
        <!--Google Admob Code-->
        <com.google.android.gms.ads.AdView
            android:id="@+id/banner_container00"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_alignParentBottom="true"
            android:layout_centerHorizontal="true"
            app:adSize="BANNER"
            app:adUnitId="@string/ad_id">

        </com.google.android.gms.ads.AdView>
        


    </LinearLayout>


</androidx.constraintlayout.widget.ConstraintLayout >

【问题讨论】:

  • 使用框架布局代替线性布局,并在 adview 中给出底部属性

标签: android android-studio admob android-linearlayout


【解决方案1】:
<androidx.constraintlayout.widget.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:layout_width="match_parent"
    android:layout_height="match_parent">


    <androidx.appcompat.widget.Toolbar
        android:id="@+id/toolbar"
        android:layout_width="match_parent"
        android:layout_height="?attr/actionBarSize"
        android:background="#E53935"
        android:textAlignment="center"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintTop_toTopOf="parent"
        app:popupTheme="@style/Theme.BangabandhuT20Cup.PopupOverlay"
        app:title="@string/privacy_policy_title"
        app:titleTextColor="#FFFFFF"></androidx.appcompat.widget.Toolbar>


    <WebView
        android:id="@+id/policyWebView"
        android:layout_width="match_parent"
        android:layout_height="0dp"
        app:layout_constraintBottom_toTopOf="@id/banner_container00"
        app:layout_constraintTop_toBottomOf="@id/toolbar" />
    <!--Google Admob Code-->
    
    <com.google.android.gms.ads.AdView
        android:id="@+id/banner_container00"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        app:adSize="BANNER"
        app:adUnitId="@string/ad_id"
        app:layout_constraintBottom_toBottomOf="parent"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintStart_toStartOf="parent"/>
    
</androidx.constraintlayout.widget.ConstraintLayout>

【讨论】:

    【解决方案2】:

    你可以使用约束布局。

    试试这个:

    <androidx.constraintlayout.widget.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:layout_width="match_parent"
    android:layout_height="match_parent"
    tools:context=".Policy.PrivacyPolicy">
    
    
    
        <androidx.appcompat.widget.Toolbar
            app:layout_constraintTop_toTopOf="parent"
            android:id="@+id/toolbar"
            android:layout_width="match_parent"
            android:layout_height="?attr/actionBarSize"
            android:background="#E53935"
            android:textAlignment="center"
            app:popupTheme="@style/Theme.BangabandhuT20Cup.PopupOverlay"
            app:title="@string/privacy_policy_title"
            app:titleTextColor="#FFFFFF"></androidx.appcompat.widget.Toolbar>
    
    
    
    <WebView
        android:id="@+id/policyWebView"
        android:layout_width="match_parent"
        android:layout_height="0dp"
        app:layout_constraintTop_toBottomOf="@id/toolbar"
        app:layout_constraintBottom_toTopOf="@id/banner_container00"/>
    
    <!--Google Admob Code-->
    <com.google.android.gms.ads.AdView
        android:id="@+id/banner_container00"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentBottom="true"
        android:layout_centerHorizontal="true"
        app:adSize="BANNER"
        app:adUnitId="ca-app-pub-2820216276511886/6822924493"
        app:layout_constraintBottom_toBottomOf="parent"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintStart_toStartOf="parent">
    
    </com.google.android.gms.ads.AdView> </androidx.constraintlayout.widget.ConstraintLayout>
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2021-07-14
      • 2012-01-15
      • 1970-01-01
      • 2017-10-23
      相关资源
      最近更新 更多