Как я могу добавить рекламный баннер внизу, не меняя LinearLayout на RelativeLayout?

Это приложение, основанное на контенте. Я пытаюсь добавить рекламный баннер внизу экрана, но я создал файл xml в Linearlayout со многими текстовыми представлениями. поэтому будет очень сложно перейти на относительную компоновку. Как я могу разместить рекламный баннер внизу экрана, не меняя много кода?

мой 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>

person Bivash Yadav    schedule 08.11.2017    source источник
comment
В вашем XML вы не упомянули высоту Textview. Я хочу знать, что он будет занимать весь экран?   -  person Arun    schedule 08.11.2017
comment
эй, все о высоте, ширине в стиле.   -  person Bivash Yadav    schedule 08.11.2017


Ответы (2)


оберните весь макет дополнительным 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>
person marmor    schedule 08.11.2017

оберните весь макет дополнительным 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>
person Munir    schedule 08.11.2017