[英]Adding ad to the bottom of linearLayout
I don't know how to put a view to the bottom of linearLayout. 我不知道如何将视图置于linearLayout的底部。 I tryed using layout_gravity="bottom", but it doesn't work.
我尝试使用layout_gravity =“ bottom”,但是它不起作用。 This is my code:
这是我的代码:
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:ads="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:paddingBottom="@dimen/activity_vertical_margin"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
android:background="@drawable/background_register_login"
tools:context="com.mcd.fantaleghe.MainActivity$PlaceholderFragment" >
<com.google.android.gms.ads.AdView android:id="@+id/adView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="bottom"
ads:adUnitId="MY_AD_UNIT_ID"
ads:adSize="BANNER"/>
</LinearLayout>
Well... you could solve this problem in several ways, but the easiest are: 嗯...您可以通过多种方式解决此问题,但最简单的方法是:
1- Change your LinearLayout to FrameLayout and erase the line android:orientation="vertical"
1-将您的LinearLayout更改为FrameLayout并删除行
android:orientation="vertical"
2- Add this to your LinearLayout android:gravity="bottom"
2-将其添加到您的LinearLayout
android:gravity="bottom"
3- You could follow this Tutorial and forget about including the adview in the xml because in the tutorial they include it programmatically. 3-您可以按照本教程进行操作,而忘记在XML中包含adview,因为在本教程中他们以编程方式将其包括在内。
I used to always use LinearLayout
because it is so simple, but you should really consider using a RealtiveLayout
to save yourself a lot of headaches. 我以前总是使用
LinearLayout
因为它是如此简单,但是您应该真正考虑使用RealtiveLayout
来省去很多麻烦。
In a RelativeLayout
you could set layout_alignParentBottom=true
or just layout_alignBelow=@+id/thingToBeBelow
and the ad will be in the right place. 在
RelativeLayout
您可以设置layout_alignParentBottom=true
或仅将layout_alignBelow=@+id/thingToBeBelow
设置为正确位置。
Using LinearLayout
as parent , You need to create a container layout to fill the other area above the AdView
like this. 使用
LinearLayout
作为父对象,您需要创建一个容器布局来填充AdView
上方的其他区域,如下所示。 You can add all your other child views inside the container layout or leave it empty. 您可以在容器布局中添加所有其他子视图或将其保留为空。
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:ads="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<LinearLayout
android:id="@+id/container"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_weight="2"/>
<com.google.android.gms.ads.AdView
android:id="@+id/welcomeAdView"
android:layout_width="match_parent"
android:layout_height="100dp"
android:layout_weight="1"
ads:adSize="SMART_BANNER"
ads:adUnitId=""/>
</LinearLayout>
Another , way is to use RelativeLayout
as parent and place the AdView
to parent bottom
另一种方法是将
RelativeLayout
用作父对象,并将AdView
置于父对象bottom
<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="match_parent"
android:layout_height="wrap_content"
ads:adSize="SMART_BANNER"
ads:adUnitId=""/>
</RelativeLayout>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.