【发布时间】:2012-01-07 11:42:08
【问题描述】:
我正在尝试在屏幕顶部显示 adMob 广告横幅。但是,如下所示,它显示在中间。有谁知道我该如何解决这个问题?
main.xml:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
ndroid:id="@+id/linearLayout"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:gravity="center"
android:background="@drawable/main_bg" >
<LinearLayout
android:id="@+id/linearLayout"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_alignParentTop="true" />
<LinearLayout
android:orientation="horizontal"
android:layout_width="fill_parent"
android:paddingTop="30dip"
android:layout_height="wrap_content"
android:gravity="center" >
<ImageButton
android:id="@+id/mnwvbutton"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginRight="15dip"
android:background="@drawable/mnwvicon" />
<ImageButton
android:id="@+id/reportsbutton"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="@drawable/reportsicon" />
</LinearLayout>
<ImageButton
android:id="@+id/mnwvshowbutton"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="@drawable/showicon"
android:paddingTop="30dip" />
</LinearLayout>
这是我在代码中添加我的 LinearLayout 的 AdView:
// Admob Banner ***********
layout = (LinearLayout)findViewById(R.id.linearLayout);
adView = new AdView(this, AdSize.BANNER, "a14ed285a63276d");
layout.addView(adView);
adView.loadAd(new AdRequest());
// *************************
这是我屏幕上显示的内容:
【问题讨论】:
-
简短回答:@+id/linearLayout 在您的布局 xml 中使用了两次,尝试给内部命名,这应该可以解决您的问题。
-
@yorkw 抱歉,这是一个复制粘贴错误……在我的代码中实际上并不是这样。我编辑了我的问题并忘记将其从父 LinearLayout 中取出。不过谢谢!