浮动操作按钮下的Admob [英] Admob under Floating Action Button

查看:68
本文介绍了浮动操作按钮下的Admob的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我对浮动按钮的位置有疑问.当我将Admob晶圆厂的广告放到上面时.我想将广告置于工厂"按钮下,但我尝试的任何方法均无效.

I have problem with position of floating action button. When i put ad from Admob fab is over it. I want to put ad under fab button but any method that I try does not work.

Image of current postion fab to ad

@layout/activity_layout:

<?xml version="1.0" encoding="utf-8"?>
<android.support.design.widget.CoordinatorLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:fitsSystemWindows="true"
    tools:context=".activities.MainActivity">

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:fitsSystemWindows="true"
        android:orientation="vertical"
        >

        <android.support.design.widget.AppBarLayout
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:theme="@style/LzTheme.AppBarOverlay">

            <android.support.v7.widget.Toolbar
                android:id="@+id/toolbar"
                android:layout_width="match_parent"
                android:layout_height="?attr/actionBarSize"
                android:background="?attr/colorPrimary"
                app:popupTheme="@style/LzTheme.PopupOverlay"/>

        </android.support.design.widget.AppBarLayout>

        <FrameLayout
            android:id="@+id/drawer_layout"
            xmlns:android="http://schemas.android.com/apk/res/android"
            xmlns:tools="http://schemas.android.com/tools"
            android:layout_width="match_parent"
            android:layout_height="match_parent">

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

            <com.google.android.gms.ads.AdView
                android:id="@+id/ad_view"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:layout_gravity="center|bottom"
                app:adSize="BANNER"
                app:adUnitId="@string/banner_ad_unit_id"/>
        </FrameLayout>
    </LinearLayout>
</android.support.design.widget.CoordinatorLayout>

@layout/content_main:

<RelativeLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:paddingBottom="@dimen/activity_vertical_margin"
    android:paddingLeft="@dimen/activity_horizontal_margin"
    android:paddingRight="@dimen/activity_horizontal_margin"
    android:paddingTop="@dimen/activity_vertical_margin"
    app:layout_behavior="@string/appbar_scrolling_view_behavior"
    tools:context=".activities.MainActivity"
    tools:showIn="@layout/activity_main">

    <FrameLayout
        android:id="@+id/FragmentContainer"
        android:layout_width="match_parent"
        android:layout_height="match_parent"/>

</RelativeLayout>

@layout/fragment:

<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
             xmlns:app="http://schemas.android.com/apk/res-auto"
             xmlns:tools="http://schemas.android.com/tools"
             android:layout_width="match_parent"
             android:layout_height="match_parent"
             tools:context="com.dsxx.test.fragments.testFragment">

    <android.support.v7.widget.RecyclerView
        android:id="@+id/Recycler"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        />

    <android.support.design.widget.FloatingActionButton
        android:id="@+id/fab_dodaj"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_gravity="bottom|end"

        app:srcCompat="@drawable/fab_plus"
        app:fabSize="normal"
        app:borderWidth="3dp"
        app:elevation="6dp"/>

</FrameLayout>

解决方案

I suggest you to create layouts that contain the fab button from Android Studio's default layout.

After creating it, there are 2 layouts:

  1. contain_main.xml

  2. activity_main.xml

Edit activity_main.xml (I put some LinearLayout in order to able to set the orientation is vertical) like this :

activity_main.xml's code :

<?xml version="1.0" encoding="utf-8"?>
<android.support.design.widget.CoordinatorLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:fitsSystemWindows="true"
    tools:context="com.appschef.mobilequeue.floatingboat.MainActivity">



    <android.support.design.widget.AppBarLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:theme="@style/AppTheme.AppBarOverlay">

        <android.support.v7.widget.Toolbar
            android:id="@+id/toolbar"
            android:layout_width="match_parent"
            android:layout_height="?attr/actionBarSize"
            android:background="?attr/colorPrimary"
            app:popupTheme="@style/AppTheme.PopupOverlay" />

    </android.support.design.widget.AppBarLayout>

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

    <!-- start from here-->
    <!-- LinearLayout for give space fab and AdView-->
    <LinearLayout
    android:orientation="vertical"
    android:gravity="bottom"
    android:layout_width="match_parent"
    android:layout_height="match_parent">

            <LinearLayout
                android:layout_width="match_parent"
                android:orientation="vertical"
                android:layout_height="wrap_content">
                <!-- linearLayour for fab button-->
                <LinearLayout
                    android:layout_weight="1"
                    android:layout_width="match_parent"
                    android:layout_height="match_parent"
                    android:gravity="right">
                    <android.support.design.widget.FloatingActionButton
                        android:id="@+id/fab"
                        android:layout_width="wrap_content"
                        android:layout_height="wrap_content"
                        android:layout_gravity="bottom|end|left"
                        android:layout_margin="@dimen/fab_margin"
                        android:src="@android:drawable/ic_dialog_email" />
                </LinearLayout>

                <!-- LinearLayour for AdView-->
                <LinearLayout
                    android:layout_weight="1"
                    android:layout_width="match_parent"
                    android:layout_height="match_parent">
                    <com.google.android.gms.ads.AdView
                        android:layout_width="match_parent"
                        android:layout_height="match_parent">
                    </com.google.android.gms.ads.AdView>
                </LinearLayout>

            </LinearLayout>
    </LinearLayout>
    <!-- end from here-->

</android.support.design.widget.CoordinatorLayout>

I have tried it and it does work well.

这篇关于浮动操作按钮下的Admob的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆