Admobs/ Adview - Advertisement at the bottom

Asked

Viewed 57 times

0

I added the ad as below. But this centered in the middle of the screen, I would like to add at the bottom. I already added android:layout_alignParentBottom="true" but nothing:

<?xml version="1.0" encoding="utf-8"?>

<include
    layout="@layout/app_bar"
    android:layout_width="match_parent"
    android:layout_height="match_parent" />

<android.support.design.widget.NavigationView
    android:id="@+id/nav_view"
    android:layout_width="wrap_content"
    android:layout_height="match_parent"
    android:layout_gravity="start"
    android:fitsSystemWindows="true"
    app:headerLayout="@layout/header_main"
    app:menu="@menu/activity_main_drawer"
    android:background="@color/colorBlue"
    app:itemTextColor="@drawable/drawer_item"
    app:itemBackground="@drawable/selector_menu"
    app:itemTextAppearance="@style/MenuItem"
    app:paddingStart="@dimen/space8"/>
<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_marginBottom="681dp"
    ads:adSize="BANNER"
    ads:adUnitId="xxxxxx"></com.google.android.gms.ads.AdView>

  • And what’s your Activity on? Relative Layout, Linear Layout...?

  • it’s just this way even...

  • I even tried to paste inside a <Linearlayout android:layout_width="wrap_content" android:layout_height="match_parent"> but it didn’t even show up anymore

1 answer

0

Option 1 - Linear Layout:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    android:orientation="vertical">

    <include
        layout="@layout/app_bar"/>


    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="0dp"
        android:layout_weight="1">


        <android.support.design.widget.NavigationView
            android:id="@+id/nav_view"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:layout_gravity="start"
            android:fitsSystemWindows="true"
            app:headerLayout="@layout/header_main"
            app:menu="@menu/activity_main_drawer"
            android:background="@color/colorBlue"
            app:itemTextColor="@drawable/drawer_item"
            app:itemBackground="@drawable/selector_menu"
            app:itemTextAppearance="@style/MenuItem"
            app:paddingStart="@dimen/space8"/>
    </LinearLayout>

    <com.google.android.gms.ads.AdView xmlns:ads="http://schemas.android.com/apk/res-auto"
        android:id="@+id/adView"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        ads:adSize="BANNER"
        ads:adUnitId="xxxxxx" />
</LinearLayout>

Option 2 - Constraintlayout:

<?xml version="1.0" encoding="utf-8"?>
<android.support.constraint.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical">


    <include layout="@layout/app_bar" />

    <android.support.design.widget.NavigationView
        android:id="@+id/nav_view"
        android:layout_width="match_parent"
        android:layout_height="0dp"
        android:background="@color/colorBlue"
        android:fitsSystemWindows="true"
        app:headerLayout="@layout/header_main"
        app:itemBackground="@drawable/selector_menu"
        app:itemTextAppearance="@style/MenuItem"
        app:itemTextColor="@drawable/drawer_item"
        app:layout_constraintBottom_toTopOf="@+id/adView"
        app:layout_constraintLeft_toLeftOf="parent"
        app:layout_constraintRight_toRightOf="parent"
        app:layout_constraintTop_toBottomOf="@id/toolbar"
        app:menu="@menu/activity_main_drawer"
        app:paddingStart="@dimen/space8" />

    <com.google.android.gms.ads.AdView xmlns:ads="http://schemas.android.com/apk/res-auto"
        android:id="@+id/adView"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        ads:adSize="BANNER"
        ads:adUnitId="xxxxxx"
        app:layout_constraintBottom_toBottomOf="parent"
        app:layout_constraintLeft_toLeftOf="parent"
        app:layout_constraintRight_toRightOf="parent" />

</android.support.constraint.ConstraintLayout>

Browser other questions tagged

You are not signed in. Login or sign up in order to post.