2015-09-03 45 views
1

我知道这个问题被问早前很多次,但所有这些工作对我的答案不是......如何在tablayout的底部显示AdMob广告

我有drawerlayout,tablayout和viewpager一个活动我想说明admob广告在viewpager的底部,这样当用户在viewpager上滑动时,广告会一直显示在底部。

这里是我的代码:

<android.support.v4.widget.DrawerLayout 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" 
    xmlns:ads="http://schemas.android.com/apk/res-auto" 
    android:id="@+id/nav_drawer" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    android:fitsSystemWindows="true" 
    tools:context=".MainActivity"> 

    <LinearLayout 
     android:id="@+id/appBarLinearLayout" 
     android:layout_width="match_parent" 
     android:layout_height="match_parent" 
     android:orientation="vertical"> 

     <android.support.design.widget.AppBarLayout 
      android:layout_width="match_parent" 
      android:layout_height="wrap_content" 
      android:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar"> 

      <include 
       android:id="@+id/app_bar" 
       layout="@layout/app_bar" /> 

      <android.support.design.widget.TabLayout 
       android:id="@+id/tab_layout" 
       android:layout_width="match_parent" 
       android:layout_height="wrap_content" 
       app:tabTextColor="@color/lightPrimaryColor" 
       app:tabSelectedTextColor="@color/textIcons"/> 

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

     <FrameLayout 
      android:id="@+id/nav_contentframe" 
      android:layout_width="match_parent" 
      android:layout_height="match_parent" 
      android:layout_marginTop="?attr/actionBarSize" 
      android:background="@android:color/background_light"/> 

    </LinearLayout> 

    <android.support.design.widget.NavigationView 
     android:id="@+id/nav_view" 
     android:layout_width="wrap_content" 
     android:layout_height="match_parent" 
     android:layout_gravity="start" 
     android:fitsSystemWindows="true" 
     app:headerLayout="@layout/drawer_header" 
     app:menu="@menu/menu_drawerlist"/> 

</android.support.v4.widget.DrawerLayout> 

我尝试添加AdMob广告像下面这样viewpager和FrameLayout里:但是这并不在屏幕上显示的广告

<LinearLayout 
    android:layout_width="fill_parent" 
    android:layout_height="wrap_content" 
    android:gravity="bottom|center_horizontal" 
    android:orientation="vertical"> 

    <include 
     android:id="@+id/admob" 
     layout="@layout/admob" /> 
</LinearLayout> 
+0

请检查我的回答.Inform我 –

回答

1

您应该使用Relative Layout并设置android:layout_alignParentBottomtrue

<RelativeLayout 
    android:layout_width="fill_parent" 
    android:layout_height="wrap_content" 
    android:layout_alignParentBottom="true"> 

    <include 
     android:id="@+id/admob" 
     layout="@layout/admob" /> 
</RelativeLayout> 

安卓layout_alignParentBottom

如果为true,使得这一观点的底部边缘父的底部边缘相匹配。容纳底部边缘。

+1

它没有任何区别:(仍不看到广告 – Jaydeep

+0

没问题你的浏览器ID是android:id =“@ + id/viewpager”是的 –

+0

是的它是android:id =“@ + id/viewpager” – Jaydeep

1

以下@IntelliJ阿米亚·的建议,我有这样的解决方案....

<android.support.v4.widget.DrawerLayout 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" 
xmlns:tools="http://schemas.android.com/tools" 
android:id="@+id/nav_drawer" 
android:layout_width="match_parent" 
android:layout_height="match_parent" 
android:fitsSystemWindows="true" 
tools:context=".MainActivity"> 

<RelativeLayout 
    android:id="@+id/appBarLinearLayout" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    android:orientation="vertical"> 

    <android.support.design.widget.AppBarLayout 
     android:id="@+id/view" 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar"> 

     <include 
      android:id="@+id/app_bar" 
      layout="@layout/app_bar" /> 

     <android.support.design.widget.TabLayout 
      android:id="@+id/tab_layout" 
      android:layout_width="match_parent" 
      android:layout_height="wrap_content" 
      app:tabSelectedTextColor="@color/textIcons" 
      app:tabTextColor="@color/lightPrimaryColor" /> 

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

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

    <FrameLayout 
     android:id="@+id/nav_contentframe" 
     android:layout_width="match_parent" 
     android:layout_height="match_parent" 
     android:layout_above="@+id/relativeLayout" 
     android:layout_below="@+id/viewpager" 
     android:background="@android:color/background_light" /> 

    <RelativeLayout 
     android:id="@+id/relativeLayout" 
     android:layout_width="fill_parent" 
     android:layout_height="wrap_content" 
     android:layout_alignParentBottom="true"> 
     <include 
      android:id="@+id/admob" 
      layout="@layout/admob" /> 
    </RelativeLayout> 


</RelativeLayout> 

<android.support.design.widget.NavigationView 
    android:id="@+id/nav_view" 
    android:layout_width="wrap_content" 
    android:layout_height="match_parent" 
    android:layout_gravity="start" 
    android:fitsSystemWindows="true" 
    app:headerLayout="@layout/drawer_header" 
    app:menu="@menu/menu_drawerlist" /> 

+0

好听(+1) –