问题描述
我试图通过注入片段放入容器放置在每个屏幕的底部的AdView。我能得到的AdView是在顶部,操作栏下方,使用的LinearLayout。我试过的RelativeLayout的各种组合,但似乎没有做出调整大小上定向的AdView棒。
I'm trying to place an adview at the bottom of every screen by injecting a fragment into a container. I can get the adview to be at the top, below the action bar, by using a LinearLayout. I've tried various combinations of RelativeLayout, but none seem to make the resizing-on-orientation adview stick.
下面是对作品的布局往上顶:
Here's the layout that works for up top:
<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的?我已经试过各种布局嵌套战略和至今都没有奏效。
And I add fragments to fragmentContainer
. How can I make the adview statically positioned at the bottom of the screen? I've tried various layout nesting strategies and none have worked so far.
横幅不应重叠或切断片段的任何部分
The banner should not overlay or cut off any part of the fragment.
推荐答案
怎么样的RelativeLayout与 alignParentBottom
属性?此外,这是不是一个好的做法,以添加其他的ViewGroup比的FrameLayout
里面的一个片段。这不会卡住或破坏你的活动,但它可能会提供一些错误。这样的事情应该做的伎俩:
What about RelativeLayout with alignParentBottom
attribute? Also, it's not a good practice to add a fragment inside another viewgroup than FrameLayout
. This will not stuck or break your activity but it might provide some bugs. Something like this should do the trick:
<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>
希望这有助于。
Hope this helps.
这篇关于机器人,在屏幕的底部定位的元件,固定的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!