It is kind of content based app.I am trying to add banner ad at the bottom of the screen but I have created the xml file in Linearlayout with many textview. so it will be very difficult to change into relative layout. How can I put banner ad at the bottom of the screen without changing much code?
my XML code :
<?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>
wrap your entire layout with an additional LinearLayout, and add the Banner ad below it:
<?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>
wrap your entire layout with an additional RelativeLayout, and add the Banner ad bottom: if you use LinearLayout it's hide your data behind at banner ads.
<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>
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.