我試圖在屏幕頂部顯示adMob廣告橫幅。但是,如下所示,它顯示在中間。任何人都知道我可以解決這個問題?Android 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>
這是我添加AdView中的我的LinearLayout在我的代碼:
// 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
@yorkw對不起,這是一個複製粘貼錯誤...在我的代碼它實際上不是那樣的。我編輯了我的問題,並忘記從父LinearLayout中取出它。雖然謝謝! – comead