繁体   English   中英

如何在不将LinearLayout更改为RelativeLayout的情况下在底部添加横幅广告?

[英]How can I add banner ad at the bottom without changing LinearLayout to RelativeLayout?

这是一种基于内容的应用程序。我正在尝试在屏幕底部添加横幅广告,但是我在Linearlayout中创建了带有许多textview的xml文件。 因此很难更改为相对布局。 如何在不更改太多代码的情况下将横幅广告放在屏幕底部?

我的XML代码:

<?xml version="1.0" encoding="utf-8"?>
  <ScrollView  xmlns:android="http://schemas.android.com/apk/res/android"
  android:layout_width="match_parent"
  android:layout_height="match_parent"
  android:fillViewport="true">
     <LinearLayout
        xmlns:android="http://schemas.android.com/apk/res/android"
        xmlns:tools="http://schemas.android.com/tools"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:background="@color/tan_background"
        android:divider="?android:dividerHorizontal"
        android:orientation="vertical"
        android:showDividers="middle"
        tools:context="com.androcreatorx.inspiringwords.MainActivity">

         <TextView
           style="@style/CategoryStyle"
           android:onClick="callAbdul"
           android:text="@string/abdul"/>
        <TextView
           style="@style/CategoryStyle"
           android:onClick="callAbraham"
           android:text="@string/Abrahm"/>
    </LinearLayout>
 </ScrollView>

用额外的LinearLayout包装整个布局,并在其下方添加横幅广告:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout 
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical">
    <ScrollView  ...>
        <LinearLayout>
        ...
        </LinearLayout>
    </ScrollView>
    <!-- ADD YOUR BANNER HERE -->
</LinearLayout>

用额外的RelativeLayout包装整个布局,并添加横幅广告底部:如果您使用LinearLayout,则会在横幅广告中隐藏数据。

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    xmlns:tools="http://schemas.android.com/tools">

    <ScrollView
        android:layout_width="match_parent"
        android:id="@+id/scrollView"
        android:layout_height="match_parent"
        android:layout_above="@+id/adView"
        android:fillViewport="true">
        <LinearLayout
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:background="@color/tan_background"
            android:divider="?android:dividerHorizontal"
            android:orientation="vertical"
            android:showDividers="middle"
            tools:context="com.androcreatorx.inspiringwords.MainActivity">




            <TextView
                style="@style/CategoryStyle"
                android:onClick="callAbdul"
                android:text="@string/abdul"/>
            <TextView
                style="@style/CategoryStyle"
                android:onClick="callAbraham"
                android:text="@string/Abrahm"/>



        </LinearLayout>

    </ScrollView>
    <com.google.android.gms.ads.AdView xmlns:ads="http://schemas.android.com/apk/res-auto"
        android:id="@+id/adView"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentBottom="true"
        android:layout_centerHorizontal="true"
        ads:adSize="SMART_BANNER"
        ads:adUnitId="@string/banner_id" />

</RelativeLayout>

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM