AdView and FloatingActionButton overlap while using CoordinatorLayout(使用 CoordinatorLayout 时 AdView 和 FloatingActionButton 重叠)
问题描述
在我的一个布局中加入新的 CoordinatorLayout 后,我遇到了 Adview 与 FloatingActionButton 重叠的问题.
After incorporating the new CoordinatorLayout in one of my layouts, I have an issue with Adviews overlapping with FloatingActionButton. 
<android.support.design.widget.CoordinatorLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    android:id="@+id/main_content"
    android:layout_width="match_parent"
    android:layout_height="match_parent">
    <android.support.design.widget.AppBarLayout
        android:id="@+id/appbar"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar">
        <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/ThemeOverlay.AppCompat.Light"
            app:layout_scrollFlags="scroll|enterAlways" />
        <android.support.design.widget.TabLayout
            android:id="@+id/tabs"
            android:layout_width="match_parent"
            android:layout_height="wrap_content" />
    </android.support.design.widget.AppBarLayout>
    <android.support.v4.view.ViewPager
        android:id="@+id/viewpager"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        app:layout_behavior="@string/appbar_scrolling_view_behavior" />
    <android.support.design.widget.FloatingActionButton
        android:id="@+id/fab"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_gravity="end|bottom"
        android:layout_margin="@dimen/fab_margin"
        android:src="QGRyYXdhYmxlL2ljX2RvbmU=" />
</android.support.design.widget.CoordinatorLayout>
来源: https://github.com/chrisbanes/cheesesquare/blob/master/app/src/main/res/layout/include_list_viewpager.xml
如果我采用相同的布局并在 FloatingActionButton 下方合并一个 AdView 它会导致 FloatingActionButton 不再与  一起使用小吃店:
If I take the same layout and incorporate an AdView below the FloatingActionButton it causes the FloatingActionButton to no longer work with the SnackBars:
<android.support.design.widget.CoordinatorLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    android:id="@+id/main_content"
    android:layout_width="match_parent"
    android:layout_height="match_parent">
    <android.support.design.widget.AppBarLayout
        android:id="@+id/appbar"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar">
        <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/ThemeOverlay.AppCompat.Light"
            app:layout_scrollFlags="scroll|enterAlways" />
        <android.support.design.widget.TabLayout
            android:id="@+id/tabs"
            android:layout_width="match_parent"
            android:layout_height="wrap_content" />
    </android.support.design.widget.AppBarLayout>
    <android.support.v4.view.ViewPager
        android:id="@+id/viewpager"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        app:layout_behavior="@string/appbar_scrolling_view_behavior" />
    <android.support.design.widget.FloatingActionButton
        android:id="@+id/fab"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_gravity="end|bottom"
        android:layout_margin="@dimen/fab_margin"
        android:src="QGRyYXdhYmxlL2ljX2RvbmU=" />
    <com.google.android.gms.ads.AdView
        android:id="@+id/ad_view"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_gravity="center|bottom"
        app:adSize="SMART_BANNER"
        app:adUnitId="@string/app_ad" />
</android.support.design.widget.CoordinatorLayout>
可重现的简单 Admob 示例:
    AdRequest adRequest = new AdRequest.Builder()
            .addTestDevice(AdRequest.DEVICE_ID_EMULATOR)
            .build();
    ((AdView)findViewById(R.id.ad_view)).loadAd(adRequest);
我有两个问题:
- 重叠视图(很可能是因为 
CoordinatorLayout扩展了FrameLayout) - 在与 
FloatingActionButton相同的布局中添加其他视图会导致它不再与SnackBar 移动或协调"
 - Overlapping Views (most likely because 
CoordinatorLayoutextendsFrameLayout) - Adding other views in the same layout as the 
FloatingActionButtoncause it to no longer to move or "coordinate" with theSnackBar 
I have two issues:
推荐答案
发布后,我决定尝试将整个 CoordinatorLayout 布局包装在一个 LinearLayout 中,看起来好好工作.也许有人知道更好的方法?
After posting, I decided to try and wrap the entire CoordinatorLayout layout in a LinearLayout and it seems to work well. Maybe someone knows of a better way?
我不确定这是不是最好的方法,因为有很多嵌套视图:
I am not sure this is the best way as there are many nested views:
<LinearLayout 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:orientation="vertical"
              tools:context=".activities.MainActivity">
<android.support.design.widget.CoordinatorLayout
    android:id="@+id/main_content"
    android:layout_width="match_parent"
    android:layout_height="match_parent">
    <android.support.design.widget.AppBarLayout
        android:id="@+id/appbar"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar">
        <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/ThemeOverlay.AppCompat.Light"
            app:layout_scrollFlags="scroll|enterAlways" />
        <android.support.design.widget.TabLayout
            android:id="@+id/tabs"
            android:layout_width="match_parent"
            android:layout_height="wrap_content" />
    </android.support.design.widget.AppBarLayout>
    <android.support.v4.view.ViewPager
        android:id="@+id/viewpager"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        app:layout_behavior="@string/appbar_scrolling_view_behavior" />
    <android.support.design.widget.FloatingActionButton
        android:id="@+id/fab"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_gravity="end|bottom"
        android:layout_margin="@dimen/fab_margin"
        android:src="QGRyYXdhYmxlL2ljX2RvbmU=" />
    <com.google.android.gms.ads.AdView
        android:id="@+id/ad_view"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_gravity="center|bottom"
        app:adSize="SMART_BANNER"
        app:adUnitId="@string/app_ad" />
</android.support.design.widget.CoordinatorLayout>
</LinearLayout>
                        这篇关于使用 CoordinatorLayout 时 AdView 和 FloatingActionButton 重叠的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:使用 CoordinatorLayout 时 AdView 和 FloatingActionButton 重叠
				
        
 
            
        - 想使用ViewPager,无法识别android.support.*? 2022-01-01
 - Android - 拆分 Drawable 2022-01-01
 - Android viewpager检测滑动超出范围 2022-01-01
 - MalformedJsonException:在第1行第1列路径中使用JsonReader.setLenient(True)接受格式错误的JSON 2022-01-01
 - android 4中的android RadioButton问题 2022-01-01
 - 如何检查发送到 Android 应用程序的 Firebase 消息的传递状态? 2022-01-01
 - Android - 我如何找出用户有多少未读电子邮件? 2022-01-01
 - 用 Swift 实现 UITextFieldDelegate 2022-01-01
 - 在测试浓缩咖啡时,Android设备不会在屏幕上启动活动 2022-01-01
 - 使用自定义动画时在 iOS9 上忽略 edgesForExtendedLayout 2022-01-01
 
				
				
				
				