2014-02-18 46 views
0

我有3個線性佈局,圖像視圖的第一個佈局,兩個按鈕的第二個佈局,即下一個,上一個和第三個我爲admob添加,但問題是我的addmob(廣告)需要額外的廣告空間,但我想顯示頂部OR圖像的底部位置,我如何設置它的XML?如何添加ad-mob(廣告橫幅)Imageview的頂部或底部?

檢查這個環節,我希望我的廣告條幅這個樣子的圖像,不採取額外的空間: http://2.bp.blogspot.com/-JhSeZI0Wy1w/TuAW-6bEtNI/AAAAAAAAAEA/SsVGJXJhQ2s/s1600/AdsOutsideScrollView.png

我的XML:

< XML版本= 「1.0」 編碼=「UTF- 8" ? >

<的LinearLayout
的xmlns:機器人= 「http://schemas.android.com/apk/res/android」

xmlns:ads="http://schemas.android.com/apk/lib/com.google.ads" 
android:layout_width="fill_parent" 
android:layout_height="fill_parent" 
android:background="#000000" 
android:gravity="fill" 
android:orientation="vertical" 
android:weightSum="100"> 

<ImageView 
    android:id="@+id/idImageViewPic" 
    android:layout_width="match_parent" 
    android:layout_height="0dp" 
    android:layout_weight="100" 
    android:adjustViewBounds="true" 
    android:background="#000000" 
    android:maxHeight="91dip" 
    android:maxWidth="47dip" 
    android:padding="10dip" 
    android:src="@drawable/p1" 
    /> 

<LinearLayout 
    android:id="@+id/layout" 
    android:layout_width="wrap_content" 
    android:layout_height="50dp" 
    > 

    <com.google.ads.AdView 
     android:id="@+id/adView" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     ads:adSize="BANNER" 
     ads:adUnitId="aasdf74546adsf" 
     ads:loadAdOnCreate="true" 
     ads:testDevices="TEST_EMULATOR, TEST_DEVICE_ID" 
     > 
    </com.google.ads.AdView> 
</LinearLayout> 

<LinearLayout 
    android:id="@+id/linearLayout1" 
    android:layout_width="fill_parent" 
    android:layout_height="wrap_content" 
    android:gravity="center" 
    > 

    <Button 
     android:id="@+id/bGeri" 
     android:layout_width="0dp" 
     android:layout_height="wrap_content" 
     android:layout_margin="5dp" 
     android:layout_weight="1" 
     android:background="#d6d6d6" 
     android:text="Previous" 
     android:textStyle="bold" > 
    </Button> 

    <Button 
     android:id="@+id/bIleri" 
     android:layout_width="0dp" 
     android:layout_height="wrap_content" 
     android:layout_margin="5dp" 
     android:layout_weight="1" 
     android:background="#d6d6d6" 
     android:text="Next" 
     android:textStyle="bold" > 
    </Button> 
</LinearLayout> 

+0

使用的FrameLayout –

+0

@AM:我不希望像點擊改變,我只是想表明添加的旗幟頂部或圖像的底部。 – Adnan

+0

也根據你的評論當我改變我的根佈局(LinearLayout)FrameLayout然後我的圖像不會顯示? – Adnan

回答

0

檢查了這一點,它可能會幫助你。

創建xml文件例如。

main.xml中

<merge 
xmlns:android="http://schemas.android.com/apk/res/android" 
xmlns:ads="http://schemas.android.com/apk/lib/com.google.ads" > 

<RelativeLayout 
    android:layout_width="fill_parent" 
    android:layout_height="fill_parent" > 

    <ImageView 
     android:id="@+id/idImageViewPic" 
     android:layout_width="wrap_content" 
     android:layout_height="fill_parent" 
     android:layout_alignParentLeft="true" 
     android:layout_alignParentRight="true" 
     android:layout_alignParentTop="true" 
     android:src="@drawable/p1" /> 

    <com.google.ads.AdView 
     android:id="@+id/adView" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:layout_alignParentTop="true" 
     ads:adSize="BANNER" 
     ads:adUnitId="a152fe7ceceb49a" 
     ads:loadAdOnCreate="true" 
     ads:testDevices="TEST_EMULATOR, TEST_DEVICE_ID" > 
    </com.google.ads.AdView> 
</RelativeLayout> 

你activity_main.xml中現在這個樣子包括這個main.xml中的文件。

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
android:layout_width="fill_parent" 
android:layout_height="fill_parent" 
android:orientation="vertical" 
android:weightSum="10" > 

<LinearLayout 
    android:layout_width="fill_parent" 
    android:layout_height="wrap_content" 
    android:layout_weight="9" 
    android:orientation="vertical" > 

    <include 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     layout="@layout/main" /> 
</LinearLayout> 

<LinearLayout 
    android:layout_width="fill_parent" 
    android:layout_height="wrap_content" 
    android:layout_weight="1" 
    android:orientation="horizontal" > 

    <Button 
    android:id="@+id/bGeri" 
    android:layout_width="0dp" 
    android:layout_height="wrap_content" 
    android:layout_margin="5dp" 
    android:layout_weight="1" 
    android:background="#d6d6d6" 
    android:text="Previous" 
    android:textStyle="bold" > 
</Button> 

    <Button 
    android:id="@+id/bIleri" 
    android:layout_width="0dp" 
    android:layout_height="wrap_content" 
    android:layout_margin="5dp" 
    android:layout_weight="1" 
    android:background="#d6d6d6" 
    android:text="Next" 
    android:textStyle="bold" > 
</Button> 
</LinearLayout> 

希望這樣可以解決你的問題

+0

Thanks Alot @ A.R。通過應用你的代碼我得到那是我想... 你節省了我的時間... 你的幫助真的很感激..保持祝福! – Adnan

+0

您最歡迎的adnan,如果回答對您有用。請接受我的回答。正如你遇到同樣問題的其他人一樣,我的答案被你接受,他們也可以從中得到幫助。接受的答案總是對其他人有用。好吧 –

+0

好吧,我明白了......! – Adnan

0

使用相對佈局,並對準父底部:

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


    <com.google.ads.AdView 
    android:id="@+id/adView" 
    android:layout_width="match_parent" 
    android:layout_height="wrap_content" 
    android:layout_alignParentBottom="true" 
    ads:adSize="BANNER" 
    ads:adUnitId="aasdf74546adsf" 
    ads:loadAdOnCreate="true" 
    ads:testDevices="TEST_EMULATOR, TEST_DEVICE_ID" 
    > 
</com.google.ads.AdView> 
</RelativeLayout> 
+0

通過應用你的代碼,即相對佈局和對齊parent bottom =「true」....現在我的圖像沒有顯示? – Adnan

+0

是的,但你需要把其他東西放在layout_height中,因爲它不再是線性佈局,而不是0dp – Tsunaze

+0

我已經更改爲wrap_content,現在圖像顯示,但我的廣告橫幅隱藏兩個按鈕的背面 – Adnan