How to get Adview below Viewpager in CoordinatorLayout

前端 未结 5 1223
慢半拍i
慢半拍i 2021-01-30 13:20

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 belo

相关标签:
5条回答
  • 2021-01-30 13:47

    as i test on real device thats work for me :Fix Height Declear On Bottom Child `

    <android.support.design.widget.CoordinatorLayout
        android:id="@+id/htab_maincontent"
        android:layout_width="match_parent"
        android:layout_above="@+id/PanelView"
        android:layout_height="match_parent">
        <!--android:fitsSystemWindows="false">-->
    
        <android.support.design.widget.AppBarLayout
            android:id="@+id/htab_appbar"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:fitsSystemWindows="true"
            android:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar">
    
            <android.support.design.widget.CollapsingToolbarLayout
                android:id="@+id/htab_collapse_toolbar"
                android:layout_width="match_parent"
                android:layout_height="256dp"
                android:fitsSystemWindows="true"
                app:contentScrim="?attr/colorPrimary"
                app:layout_scrollFlags="scroll|exitUntilCollapsed">
    
                <ImageView
                    android:id="@+id/htab_header"
                    android:layout_width="match_parent"
                    android:layout_height="match_parent"
                    android:background="@drawable/title_panel_main"
                    android:fitsSystemWindows="true"
                    android:scaleType="centerCrop"
                    app:layout_collapseMode="parallax" />
    
                <android.support.v7.widget.Toolbar
                    android:id="@+id/htab_toolbar"
                    android:layout_width="match_parent"
                    android:layout_height="104dp"
                    android:gravity="top"
                    android:minHeight="?attr/actionBarSize"
                    app:layout_collapseMode="pin"
                    app:popupTheme="@style/ThemeOverlay.AppCompat.Light"
                    app:titleMarginTop="13dp" />
    
                <android.support.design.widget.TabLayout
                    android:id="@+id/htab_tabs"
                    android:layout_width="match_parent"
                    android:layout_height="?attr/actionBarSize"
                    android:layout_gravity="bottom"
                    app:tabIndicatorColor="@android:color/white" />
            </android.support.design.widget.CollapsingToolbarLayout>
        </android.support.design.widget.AppBarLayout>
    
    
        <android.support.v4.view.ViewPager
            android:id="@+id/tab_viewpager"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            app:layout_behavior="@string/appbar_scrolling_view_behavior" />
    </android.support.design.widget.CoordinatorLayout>
    
    
    <LinearLayout
        android:id="@+id/PanelView"
        android:layout_width="match_parent"
        android:layout_height="70dp"
        android:orientation="horizontal"
        android:padding="7dp"
        android:layout_alignParentBottom="true"
        android:visibility="visible">
    
    
    
        <TextView
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_marginRight="10dp"
             />
    </LinearLayout>
    </RelativeLayout>`
    

    Hope Help You

    0 讨论(0)
  • 2021-01-30 13:51

    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.

    <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>
    
    0 讨论(0)
  • 2021-01-30 13:59

    Put ViewPager and Adview inside a another LinearLayout as below:

        <LinearLayout 
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:orientation="vertical">
         <android.support.v4.view.ViewPager
                android:id="@+id/viewPager"
                android:layout_width="match_parent"
                android:layout_height="0dp"
                android:layout_weight="1"
                app:layout_behavior="@string/appbar_scrolling_view_behavior"/>
    
            <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="@string/banner_ad_unit_id"
                android:layout_gravity="center|bottom"
                />
        </LinearLayout>
    
    0 讨论(0)
  • 2021-01-30 14:00

    This worked for me : just put inside the ViewPager the app:layout_behavior :

    <android.support.v4.view.ViewPager
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        app:layout_behavior="@string/appbar_scrolling_view_behavior"
    
    0 讨论(0)
  • 2021-01-30 14:02

    I tried the answer by @AvishekV but that didn't solve my problem. But I took THE IDEA of putting CoordinatorLayout and Adview inside a parent layout which in my case was ConstraintLayout. Below is the structure

    <android.support.constraint.ConstraintLayout 
        xmlns:android="http://schemas.android.com/apk/res/android"
        xmlns:ads="http://schemas.android.com/apk/res-auto"
        xmlns:app="http://schemas.android.com/apk/res-auto"
        android:layout_width="match_parent"
        android:layout_height="match_parent">
    
       <android.support.design.widget.CoordinatorLayout
           android:id="@+id/content"
           android:layout_width="0dp"
           android:layout_height="0dp"
           android:fitsSystemWindows="true"
           app:layout_constraintBottom_toTopOf="@+id/adView"
           app:layout_constraintEnd_toEndOf="parent"
           app:layout_constraintStart_toStartOf="parent"
           app:layout_constraintTop_toTopOf="parent">
    
            <android.support.design.widget.AppBarLayout>
               //CollapsingToolbarLayout
               //ConstraintLayout, if you need to put anything inside collpasingtoolbar
               //Toolbar
               //TabLayout
            </android.support.design.widget.AppBarLayout>
    
            <android.support.v4.view.ViewPager
            android:id="@+id/container"
            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="wrap_content"
        android:layout_height="wrap_content"
        ads:adSize="SMART_BANNER"
        ads:adUnitId="your adunit id"
        app:layout_constraintBottom_toBottomOf="parent"
        app:layout_constraintHorizontal_bias="1.0"
        app:layout_constraintLeft_toLeftOf="parent"
        app:layout_constraintRight_toRightOf="parent"
        app:layout_constraintStart_toStartOf="parent" />
    
    </android.support.constraint.ConstraintLayout>
    
    0 讨论(0)
提交回复
热议问题