如何在制表符和寻呼机活动中对齐父级底部

时间:2015-09-15 08:43:21

标签: android xml layout admob

我试图冻结我页面底部的Admob横幅,类似于此图片 -

enter image description here

但是,我的活动包含标签和多个页面。每当我尝试将adView放在底部时,我都会遇到一些参数错误。如何插入adView并将其与布局底部对齐?我也尝试过RelativeLayout对手,但无济于事。

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

2 个答案:

答案 0 :(得分:1)

使用RelativeLayout而不是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>

android:layout_alignParentTop="true"用于com.tk.cocguide.tabs.SlidingTabLayout

android:layout_below="@+id/tabs"         android:layout_above="@+id/adView"

中的android.support.v4.view.ViewPager

答案 1 :(得分:1)

使用RelativeLayout根布局/家长和/或Adview ),然后设置 android:layout_alignParentBottom 。试试这种方式我希望它会对您有所帮助。< / p>

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

有关详细信息,请查看

  

How to align views at the bottom of the screen?