2014-04-18 105 views
0

我试图通过将一个片段注入容器来在每个屏幕的底部放置一个adview。通过使用LinearLayout,我可以将adview放置在操作栏下方的顶部。我尝试过使用RelativeLayout的各种组合,但似乎没有一种方法可以调整面向大小的Adview标签。Android,在屏幕底部定位一个元素,固定

这里有长达顶级作品的布局:

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
      android:id="@+id/fragmentContainer" 
      android:layout_width="match_parent" 
      android:layout_height="match_parent" 
      android:orientation="vertical" 
      xmlns:ads="http://schemas.android.com/apk/res-auto" 
     > 

    <com.google.android.gms.ads.AdView android:id="@+id/adView" 
             android:layout_width="wrap_content" 
             android:layout_height="wrap_content" 
             ads:adSize="SMART_BANNER"/> 
</LinearLayout> 

我片段加入fragmentContainer。我怎样才能使adview静态定位在屏幕的底部?我尝试过各种布局嵌套策略,至今都没有成功。

横幅不应该覆盖或切断片段的任何部分。

回答

3

RelativeLayout与alignParentBottom属性呢?另外,在FrameLayout之外的另一个视图组中添加片段并不是一个好习惯。这不会卡住或破坏你的活动,但它可能会提供一些错误。像这样的应该做的伎俩:

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    xmlns:ads="http://schemas.android.com/apk/res-auto" > 

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

    <FrameLayout 
     android:id="@+id/fragmentContainer" 
     android:layout_width="match_parent" 
     android:layout_height="match_parent" 
     android:layout_above="@id/adView" /> 

</RelativeLayout> 

希望这会有所帮助。

+0

这会导致横幅覆盖视图并切断片段中任何内容的底部。 –

+0

@StefanKendall我根据您的需求更新了我的答案。通常情况下,片段将通过'layout_above'属性保持在adView之上。让我知道这是否是你所期望的。 – Fllo

+0

我会试一试 –

相关问题