2012-08-22 28 views
0

我使用eclipse製作了我的第一個Android應用程序。現在我需要安排佈局,因爲我的佈局現在通過WebView在主要內容上顯示Google AdMob廣告。另外,當我旋轉手機並進入橫向模式時,AdMob廣告只位於屏幕的一半。我該如何解決這個問題,以及如何讓Google AdMob擁有自己的空間,就像進度條一樣,不會在WebView上顯示。這是我的佈局:Android:我需要安排我的應用程序的佈局

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

<ProgressBar 
android:id="@+id/web_view_progress_bar" 
style="?android:attr/progressBarStyleHorizontal" 
android:layout_width="fill_parent" 
android:layout_height="15dip" 
android:padding="2dip" 
android:progressDrawable="@drawable/colorprogress" /> 

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" 
xmlns:ads="http://schemas.android.com/apk/lib/com.google.ads" 
android:orientation="vertical" 
android:layout_width="fill_parent" 
android:layout_height="fill_parent"> 

<ImageView 
android:id="@+id/splash_view" 
android:layout_width="match_parent" 
android:layout_height="match_parent" 
android:contentDescription="@string/desc" 
android:scaleType="fitXY" 
android:src="@drawable/splash" 
android:visibility="visible" /> 

<WebView android:id="@+id/web_view" 
android:layout_width="match_parent" 
android:layout_height="match_parent" 
android:scrollbars="none" 
android:visibility="gone" /> 

<com.google.ads.AdView android:id="@+id/adView" 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    ads:adUnitId="a1500108406597c" 
    ads:adSize="BANNER" 
    ads:loadAdsOnCreate="true" 
    android:layout_alignParentBottom="true"/> 

</RelativeLayout> 
</LinearLayout> 

回答

0

你已經把AdViewRelativeLayout,它將把它放在項目的頂部在那裏之內。

你只想把它放在LinearLayout;我向您展示了必須做什麼,如果你想它的ProgressBarRelativeLayout之間:

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

    <ProgressBar 
    android:id="@+id/web_view_progress_bar" 
    style="?android:attr/progressBarStyleHorizontal" 
    android:layout_width="fill_parent" 
    android:layout_height="15dip" 
    android:padding="2dip" 
    android:progressDrawable="@drawable/colorprogress" /> 

    <com.google.ads.AdView android:id="@+id/adView" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     ads:adUnitId="a1500108406597c" 
     ads:adSize="BANNER" 
     ads:loadAdsOnCreate="true" 
     android:layout_alignParentBottom="true"/> 

    <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    xmlns:ads="http://schemas.android.com/apk/lib/com.google.ads" 
    android:orientation="vertical" 
    android:layout_width="fill_parent" 
    android:layout_height="fill_parent"> 

     <ImageView 
     android:id="@+id/splash_view" 
     android:layout_width="match_parent" 
     android:layout_height="match_parent" 
     android:contentDescription="@string/desc" 
     android:scaleType="fitXY" 
     android:src="@drawable/splash" 
     android:visibility="visible" /> 

     <WebView android:id="@+id/web_view" 
     android:layout_width="match_parent" 
     android:layout_height="match_parent" 
     android:scrollbars="none" 
     android:visibility="gone" /> 

    </RelativeLayout> 
</LinearLayout> 

當然,如果你在底部希望它來代替,把它放在</LinearLayout>標籤上面。

+0

感謝您的回覆。我將admob代碼放在之上,但現在廣告不會顯示出來。我不知道問題在哪裏!? –

+0

可能是RelativeLayout高度的fill_parent存在干擾。相反,您可能必須將其設置爲「0」,並將「1」設置爲重量。 – Eric