2013-06-25 104 views
1

我是Android新手,我試圖學習如何將Admob添加到現有的應用程序中。使用Admob SDK說明,我已經能夠在我嘗試過的幾個應用程序上成功完成此操作。我有一個,但是對於我的生活,我不能像它應該去屏幕的底部。我知道它在main.xml中的東西,但我無法弄清楚。如何讓Admob廣告屏幕脫離屏幕中心?

下面是代碼我現在有把廣告塊就在屏幕的中心:

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

<ImageView android:layout_width="fill_parent" 
    android:layout_height="fill_parent" 
    android:src="@drawable/eight_ball" 
    android:layout_gravity="center_vertical" 
    android:layout_margin="10px" /> 
    <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
     android:id="@+id/linearLayout" 
     android:orientation="vertical" 
     android:layout_width="fill_parent" 
     android:layout_height="fill_parent" 
     android:gravity="center"> 
     <TextView android:id="@+id/MessageTextView" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:layout_gravity="center" 
      android:background="@drawable/triangle" 
      android:text="@string/shake_me_caption" 
      android:focusable="false" 
      android:gravity="center_vertical|center" 
          android:layout_marginTop="14dip"> 
     </TextView> 
</LinearLayout> 
</FrameLayout> 

而我的主要活動的java文件,與該交易的一部分:

@Override 
public void onCreate(Bundle savedInstanceState) { 
    super.onCreate(savedInstanceState); 
    setContentView(R.layout.main); 
    initialization(); 
    // Adding AdMob banner 
    adView = new AdView(this, AdSize.BANNER, MY_AD_UNIT_ID); 
    LinearLayout layout = (LinearLayout)findViewById(R.id.linearLayout); 
    layout.addView(adView); 
    adView.loadAd(new AdRequest()); 
} 

正如我所說我非常確定它的main.xml需要工作(可能也對主要活動中的代碼進行了一些調整),但不管我嘗試過的廣告塊是保留在中心還是消失共。

在此先感謝。

回答

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

把這段代碼放在你的xml文件中,你想放置的地方。你不需要寫你在java文件中寫的代碼。

只需將此代碼插入到xml即可。就這樣。 乾杯。

+0

非常感謝您的工作。我不敢相信這很簡單。我想我有很多東西要學。 :) – user2518383

+0

你的歡迎朋友:) – posha