How to align parent bottom in tabs and pager activity

I'm trying to freeze my Admob banner at the bottom of my page, similar to this picture -

在这里输入图像描述

However, my activity contains tabs and multiple pages. Whenever I try to put the adView at the bottom, I get some param errors. How can I insert the adView and align it to the bottom of the layout? I've tried the RelativeLayout counterpart as well, but to no avail.

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    android:orientation="vertical"
    android:layout_width="match_parent"
    android:windowActionBar="false"
    xmlns:ads="http://schemas.android.com/apk/res-auto"
    android:layout_height="match_parent">


    <com.tk.cocguide.tabs.SlidingTabLayout
        android:id="@+id/tabs"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:elevation="2dp"
        android:background="@color/cyan_900"/>

      <android.support.v4.view.ViewPager
        android:id="@+id/pager"
        android:layout_height="match_parent"
        android:layout_width="match_parent"
        android:layout_weight="1">

      </android.support.v4.view.ViewPager>

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


</LinearLayout>

Use RelativeLayout instead of LinearLayout

<RelativeLayout 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:orientation="vertical"
android:windowActionBar="false">


<com.tk.cocguide.tabs.SlidingTabLayout
    android:id="@+id/tabs"
    android:layout_alignParentTop="true"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:elevation="2dp" />

<android.support.v4.view.ViewPager
    android:id="@+id/pager"
    android:layout_width="match_parent"
    android:layout_below="@+id/tabs"
    android:layout_above="@+id/adView"
    android:layout_height="0dp"
    android:layout_weight="1">

</android.support.v4.view.ViewPager>

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

use android:layout_alignParentTop="true" for com.tk.cocguide.tabs.SlidingTabLayout

and android:layout_below="@+id/tabs" android:layout_above="@+id/adView" in android.support.v4.view.ViewPager


Use RelativeLayout ( Root layout/Parent and or Adview )and then set android:layout_alignParentBottom .Try this way i hope it will helps you.

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

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

        </RelativeLayout>

For more information have a look here

How to align views at the bottom of the screen?

链接地址: http://www.djcxy.com/p/93232.html

上一篇: Android LinearLayout填充

下一篇: 如何在选项卡和传呼机活动中对齐父级底部