Android AdMob位置屏幕底部无法正常工作

时间:2011-05-28 21:41:45

标签: android android-layout admob

相对布局有效,但当我这样做时,我的所有textview和togglebuttons都会进入屏幕的左上角,请帮忙。

main.xml中

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"   
android:layout_height="fill_parent"
android:background="@drawable/pattern_carbon_fiber_dark">

<com.google.ads.AdView
xmlns:ads="http://schemas.android.com/apk/lib/com.google.ads" 
android:id="@+id/adView"
android:layout_width="fill_parent" 
ads:adSize="BANNER"
ads:adUnitId="xxxxxxxxxxxxxx"
ads:loadAdOnCreate="true"
android:visibility="visible"
android:layout_alignParentBottom="true"
android:layout_gravity="bottom" 
android:layout_height="wrap_content">
</com.google.ads.AdView>

<TextView android:text="Silent Mode" android:layout_height="wrap_content"           android:id="@+id/textView1" android:layout_width="wrap_content"></TextView>
<ToggleButton android:layout_height="wrap_content" android:text="Silent Mode" android:id="@+id/silentbutton" android:layout_width="wrap_content" android:textOff="OFF" android:textOn="ON"></ToggleButton>
<TextView android:id="@+id/textView2" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="Wifi "></TextView>
<ToggleButton android:layout_width="wrap_content" android:text="ToggleButton" android:layout_height="wrap_content" android:id="@+id/wifibutton"></ToggleButton>
<TextView android:layout_width="wrap_content" android:id="@+id/textView3" android:text="@string/network" android:layout_height="wrap_content"></TextView>
<TextView android:layout_gravity="center" android:text="@string/blank" android:layout_height="wrap_content" android:layout_width="wrap_content" android:id="@+id/textView4"></TextView>          

</RelativeLayout>  

当我进行线性布局时,切换按钮和文本视图很好,但广告会转到屏幕中心。请帮忙。

谢谢!

1 个答案:

答案 0 :(得分:1)

来自android javadoc关于linearlayout.setGravity:

public void setGravity(int gravity)

自:API级别1 描述子视图的定位方式。默认为GRAVITY_TOP。 如果此布局具有垂直方向,则如果有额外的垂直空间,则控制放置所有子视图的位置。 如果此布局具有HORIZONTAL方向,则控制对齐孩子们 相关的XML属性

机器人:重力 参数

重力参见重力


所以它根本不适合使用线性布局。我建议你

  • 更改广告组件的顺序
  • 或使用相对布局,然后通常可以更好地控制组件定位。

此致 斯特凡

相关问题