如何在浮动操作按钮下添加AdMob

时间:2016-11-10 11:15:57

标签: android

我对FloatingActionButton的位置有疑问。当我从AdMob发布广告时,我想将广告放在制作按钮下,但我尝试的任何方法都不起作用。

当前位置的图像:

Image of current postion

main_activity:

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:ads="http://schemas.android.com/apk/res-auto"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:paddingBottom="@dimen/activity_vertical_margin"
    android:paddingLeft="@dimen/activity_horizontal_margin"
    android:paddingRight="@dimen/activity_horizontal_margin"
    android:paddingTop="@dimen/activity_vertical_margin"
    android:clipToPadding="false">

<com.google.android.gms.ads.AdView
    android:id="@+id/adView"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:layout_centerHorizontal="true"
    android:layout_alignParentBottom="true"
    ads:adSize="BANNER"
    ads:adUnitId="@string/banner_home_footer">
</com.google.android.gms.ads.AdView>

<android.support.v7.widget.RecyclerView
    android:id="@+id/notes_recycler_view"
    android:scrollbars="vertical"
    android:layout_alignParentTop="true"
    android:layout_alignParentLeft="true"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:paddingBottom="80dp"
    android:clipToPadding="false"/>

<TextView
    android:id="@+id/empty_text_view"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:gravity="center"
    android:visibility="gone"
    android:text="@string/no_notes"/>

<android.support.design.widget.FloatingActionButton
    android:id="@+id/add_button"
    android:src="@drawable/add"
    android:layout_alignParentBottom="true"
    android:layout_alignParentRight="true"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    app:backgroundTint="#e10000"
    app:fabSize="normal"
    app:borderWidth="0dp"
    app:elevation="6dp"
    app:pressedTranslationZ="12dp"
    android:onClick="addNote"/>
</RelativeLayout>

1 个答案:

答案 0 :(得分:0)

使用layout_above属性

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:ads="http://schemas.android.com/apk/res-auto"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:paddingBottom="@dimen/activity_vertical_margin"
    android:paddingLeft="@dimen/activity_horizontal_margin"
    android:paddingRight="@dimen/activity_horizontal_margin"
    android:paddingTop="@dimen/activity_vertical_margin"
    android:clipToPadding="false">

<android.support.design.widget.FloatingActionButton
    android:id="@+id/add_button"
    android:src="@drawable/add"
<!--Removed -->
    android:layout_alignParentRight="true"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    app:backgroundTint="#e10000"
    app:fabSize="normal"
    app:borderWidth="0dp"
    app:elevation="6dp"
    app:pressedTranslationZ="12dp"
    android:onClick="addNote"
<!--Added-->
android:layout_above="@+id/adView"
        />

<com.google.android.gms.ads.AdView
    android:id="@+id/adView"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:layout_centerHorizontal="true"
    android:layout_alignParentBottom="true"
    ads:adSize="BANNER"
    ads:adUnitId="@string/banner_home_footer">
</com.google.android.gms.ads.AdView>

<android.support.v7.widget.RecyclerView
    android:id="@+id/notes_recycler_view"
    android:scrollbars="vertical"
    android:layout_alignParentTop="true"
    android:layout_alignParentLeft="true"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:paddingBottom="80dp"
    android:clipToPadding="false"/>

<TextView
    android:id="@+id/empty_text_view"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:gravity="center"
    android:visibility="gone"
    android:text="@string/no_notes"/>


</RelativeLayout>