2012-01-23 90 views
0

如何防止我的Android屏幕在顯示頁面時向下移動並接收到第一次添加?Android屏幕隨AdView移動

當視圖第一次顯示時,屏幕顯示正常,然後顯示廣告,屏幕向下移動幾行。

這是我的代碼。

<?xml version="1.0" encoding="utf-8"?> 
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
xmlns:ads="http://schemas.android.com/apk/lib/com.google.ads" 
android:id="@+id/LinearLayout1" 
android:layout_width="match_parent" 
android:layout_height="match_parent" 
android:background="@drawable/background3" 
android:orientation="vertical" > 

<com.google.ads.AdView 
    android:id="@+id/adView" 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:layout_marginTop="2dp" 
    android:layout_gravity="top" 
    ads:adSize="BANNER" 
    ads:adUnitId="xxxxxxxxxx" 
    android:gravity="center" 
    ads:loadAdOnCreate="true" > 
</com.google.ads.AdView> 

<TableRow 
    android:id="@+id/tableRow2" 
    android:layout_width="fill_parent" 
    android:layout_height="50dp" 
    android:layout_marginTop="34dp" > 

    <EditText 
     android:id="@+id/editText1" 
     android:layout_width="fill_parent" 
     android:layout_height="wrap_content" 
     android:layout_weight="1" /> 

    <Button 
     android:id="@+id/button1" 
     android:layout_width="fill_parent" 
     android:layout_height="wrap_content" 
     android:layout_weight="3" 
     android:text="Start" /> 

</TableRow> 

</LinearLayout> 

TIA,三分球

回答

0

我沒有與廣告太多經驗。但嚴格來說,從View的角度來看,似乎發生的事情是adView在加載前設置爲View.GONE。這意味着在將其他視圖放入父項時,其空間被忽略。

我不知道你怎麼可以不這樣做。但是我會嘗試在你的xml中明確地將它設置爲android:visibility="invisible",然後在你的java中你必須在它加載後才能看到它。 「看不見」就像走了一樣,但它告訴家長要尊重你看到的空間。

也許loadOnCreate屬性會導致您看到的行爲?也許值得嘗試一下,不要在onCreate中手動加載它。