浏览报低于Viewpager在CoordinatorLayout

浏览报低于Viewpager在CoordinatorLayout

本文介绍了如何获得AD浏览报低于Viewpager在CoordinatorLayout的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

AD浏览报是出现在 ViewPager 所以其堵在应用程序中内容的时刻。我怎样才能获得 AD浏览报出现下面的 ViewPager ,而不是内部。

我试图把 AD浏览报 RelativeLayout的下面的 ViewPager 但随后的 AD浏览报不显示在所有。

 < LinearLayout中的xmlns:机器人=htt​​p://schemas.android.com/apk/res/android
的xmlns:工具=htt​​p://schemas.android.com/tool​​s
的xmlns:程序=htt​​p://schemas.android.com/apk/res-auto
的xmlns:广告=htt​​p://schemas.android.com/apk/res-auto
机器人:layout_width =match_parent
机器人:layout_height =match_parent
机器人:方向=垂直
工具:上下文=com.candyx.testapp.Activity>

< android.support.design.widget.CoordinatorLayout的xmlns:机器人=htt​​p://schemas.android.com/apk/res/android
    的xmlns:程序=htt​​p://schemas.android.com/apk/res-auto
    机器人:ID =@ + ID / main_content
    机器人:layout_width =match_parent
    机器人:layout_height =match_parent>

    < android.support.design.widget.AppBarLayout
        机器人:layout_width =match_parent
        机器人:layout_height =WRAP_CONTENT
        机器人:背景=@可绘制/ main_button_background>

        < android.support.v7.widget.Toolbar
            的xmlns:机器人=htt​​p://schemas.android.com/apk/res/android
            机器人:ID =@ + ID /工具栏
            机器人:layout_width =match_parent
            机器人:layout_height =?ATTR / actionBarSize
            应用程序:layout_scrollFlags =滚动| enterAlways/>

        < android.support.design.widget.TabLayout
            机器人:ID =@ + ID /标签
            机器人:layout_width =match_parent
            机器人:layout_height =WRAP_CONTENT
            应用程序:tabMode =滚动
            应用程序:tabGravity =补
            应用程序:tabIndicatorColor =@色/ colorTabIndicator
            应用程序:tabIndicatorHeight =3DP/>

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


    < android.support.v4.view.ViewPager
        机器人:ID =@ + ID / viewPager
        机器人:layout_width =match_parent
        机器人:layout_height =match_parent
        应用程序:layout_behavior =@字符串/ appbar_scrolling_view_behavior/>

    < com.google.android.gms.ads.AdView
        机器人:ID =@ + ID / AD浏览报
        机器人:layout_width =match_parent
        机器人:layout_height =WRAP_CONTENT
        广告:adSize =大旗
        广告:adUnitId =@字符串/ banner_ad_unit_id
        机器人:layout_gravity =中心|底/>

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

< / LinearLayout中>
 

解决方案

您可以添加 ViewPager AD浏览报 RelativeLayout的并指定安卓layout_above =@ + ID / AD浏览报属性 ViewPager AD浏览报不会阻止 ViewPager 内容。

下面的布局应该可以正常工作

 < RelativeLayout的
机器人:layout_width =match_parent
机器人:layout_height =match_parent>

< android.support.v4.view.ViewPager
    机器人:ID =@ + ID / viewPager
    机器人:layout_width =match_parent
    机器人:layout_height =match_parent
    机器人:layout_above =@ + ID / AD浏览报
    应用程序:layout_behavior =@字符串/ appbar_scrolling_view_behavior/>

< com.google.android.gms.ads.AdView
    机器人:ID =@ + ID / AD浏览报
    机器人:layout_width =match_parent
    机器人:layout_height =WRAP_CONTENT
    机器人:layout_alignParentBottom =真
    机器人:layout_centerHorizo​​ntal =真
    机器人:layout_gravity =中心|底
    广告:adSize =大旗
    广告:adUnitId =@字符串/ banner_ad_unit_id/>
< / RelativeLayout的>
 

编辑:如何把 AD浏览报之外 CoordinatorLayout 。请问下面的布局为你工作?

 < RelativeLayout的的xmlns:机器人=htt​​p://schemas.android.com/apk/res/android
    的xmlns:工具=htt​​p://schemas.android.com/tool​​s
    的xmlns:程序=htt​​p://schemas.android.com/apk/res-auto
    的xmlns:广告=htt​​p://schemas.android.com/apk/res-auto
    机器人:layout_width =match_parent
    机器人:layout_height =match_parent
    工具:上下文=com.candyx.testapp.Activity>

    < android.support.design.widget.CoordinatorLayout的xmlns:机器人=htt​​p://schemas.android.com/apk/res/android
        的xmlns:程序=htt​​p://schemas.android.com/apk/res-auto
        机器人:ID =@ + ID / main_content
        机器人:layout_width =match_parent
        机器人:layout_height =match_parent
        机器人:layout_above =@ + ID / AD浏览报>

        < android.support.design.widget.AppBarLayout
            机器人:layout_width =match_parent
            机器人:layout_height =WRAP_CONTENT
            机器人:背景=@可绘制/ main_button_background>

            < android.support.v7.widget.Toolbar
                的xmlns:机器人=htt​​p://schemas.android.com/apk/res/android
                机器人:ID =@ + ID /工具栏
                机器人:layout_width =match_parent
                机器人:layout_height =?ATTR / actionBarSize
                应用程序:layout_scrollFlags =滚动| enterAlways/>

            < android.support.design.widget.TabLayout
                机器人:ID =@ + ID /标签
                机器人:layout_width =match_parent
                机器人:layout_height =WRAP_CONTENT
                应用程序:tabMode =滚动
                应用程序:tabGravity =补
                应用程序:tabIndicatorColor =@色/ colorTabIndicator
                应用程序:tabIndicatorHeight =3DP/>

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

        < android.support.v4.view.ViewPager
            机器人:ID =@ + ID / viewPager
            机器人:layout_width =match_parent
            机器人:layout_height =match_parent
            应用程序:layout_behavior =@字符串/ appbar_scrolling_view_behavior/>

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

    < com.google.android.gms.ads.AdView
        机器人:ID =@ ID / AD浏览报
        机器人:layout_width =match_parent
        机器人:layout_height =WRAP_CONTENT
        广告:adSize =大旗
        广告:adUnitId =@字符串/ banner_ad_unit_id
        机器人:layout_gravity =中心|底
        机器人:layout_alignParentBottom =真/>

< / RelativeLayout的>
 

At the moment the AdView is appearing inside the ViewPager so its blocking the content in the app. How can I get the AdView to appear below the ViewPager and not inside.

I have tried to put the AdView in a RelativeLayout below the ViewPager but then the AdView doesn't show at all.

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:ads="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
tools:context="com.candyx.testapp.Activity">

<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:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:background="@drawable/main_button_background">

        <android.support.v7.widget.Toolbar
            xmlns:android="http://schemas.android.com/apk/res/android"
            android:id="@+id/toolbar"
            android:layout_width="match_parent"
            android:layout_height="?attr/actionBarSize"
            app:layout_scrollFlags="scroll|enterAlways"/>

        <android.support.design.widget.TabLayout
            android:id="@+id/tabs"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            app:tabMode="scrollable"
            app:tabGravity="fill"
            app:tabIndicatorColor="@color/colorTabIndicator"
            app:tabIndicatorHeight="3dp"/>

    </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"/>

    <com.google.android.gms.ads.AdView
        android:id="@+id/adView"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        ads:adSize="BANNER"
        ads:adUnitId="@string/banner_ad_unit_id"
        android:layout_gravity="center|bottom"/>

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

</LinearLayout>
解决方案

You can add ViewPager and AdView inside RelativeLayout and specify android:layout_above="@+id/adView" property to ViewPager so that adView doesn't block the ViewPager contents.

Below layout should work fine

<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent">

<android.support.v4.view.ViewPager
    android:id="@+id/viewPager"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:layout_above="@+id/adView"
    app:layout_behavior="@string/appbar_scrolling_view_behavior" />

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

Edit : How about putting adView outside CoordinatorLayout. Does below layout work for you?

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:ads="http://schemas.android.com/apk/res-auto"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    tools:context="com.candyx.testapp.Activity">

    <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:layout_above="@+id/adView">

        <android.support.design.widget.AppBarLayout
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:background="@drawable/main_button_background">

            <android.support.v7.widget.Toolbar
                xmlns:android="http://schemas.android.com/apk/res/android"
                android:id="@+id/toolbar"
                android:layout_width="match_parent"
                android:layout_height="?attr/actionBarSize"
                app:layout_scrollFlags="scroll|enterAlways"/>

            <android.support.design.widget.TabLayout
                android:id="@+id/tabs"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                app:tabMode="scrollable"
                app:tabGravity="fill"
                app:tabIndicatorColor="@color/colorTabIndicator"
                app:tabIndicatorHeight="3dp"/>

        </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.CoordinatorLayout>

    <com.google.android.gms.ads.AdView
        android:id="@id/adView"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        ads:adSize="BANNER"
        ads:adUnitId="@string/banner_ad_unit_id"
        android:layout_gravity="center|bottom"
        android:layout_alignParentBottom="true"/>

</RelativeLayout>

这篇关于如何获得AD浏览报低于Viewpager在CoordinatorLayout的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-02 17:59