2013-11-27 46 views
1

設置佈局時出現問題。AD加載期間的佈局問題

廣告之前加載,它看起來是這樣的:加載廣告

enter image description here

後,一切都將它的位置。它看起來像這樣(糾正)

enter image description here

有誰知道如何解決這個問題?這不僅僅是在AD加載的時候看起來「醜陋」,AD也可能永遠不會加載,並且佈局可以永遠保持這種方式(第一圖像)。

有什麼建議嗎?

我有這樣的XML佈局:

<com.example.touch.TouchImageView android:id="@+id/mytouchview" 
    android:layout_height="match_parent" 
    android:layout_width="match_parent" 
    android:layout_marginLeft="5dp" 
    android:layout_marginRight="5dp" 
    android:layout_marginTop="5dp" 
    android:layout_above="@+id/relat" 
    /> 

    <RelativeLayout 
     android:id="@id/relat" 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:paddingLeft="10dp" 
     android:paddingRight="10dp" 
     android:layout_above="@+id/myAdView" 
     > 

     <ImageButton android:layout_width="wrap_content" android:layout_height="wrap_content" android:padding="3dp" android:layout_alignParentLeft="true" 
     android:background="@null" android:src="@drawable/previous" android:id="@+id/previous"/> 

     <TextView android:layout_height="wrap_content" android:layout_width="wrap_content" android:textSize="20sp" android:text="2/15" 
      android:id="@+id/memeNumber" android:layout_centerInParent="true" android:layout_margin="5dp"/> 


     <ImageButton android:layout_width="wrap_content" android:layout_height="wrap_content" android:padding="3dp" android:layout_alignParentRight="true" 
     android:background="@null" android:src="@drawable/next" android:id="@+id/next"/> 


    </RelativeLayout> 



<com.csjy.sfwn148282.AdView 
    xmlns:ap="http://schemas.android.com/apk/res-auto" 
    android:id="@id/myAdView" 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    ap:animation="fade" 
    ap:placementType="interstitial" 
    ap:banner_type="inappad" 
    ap:test_mode="true" 
    ap:canShowMR="false" 
    android:layout_alignParentBottom="true" 
/> 

編輯:

後@Szymon回答佈局看起來是這樣的。沒關係,因爲加載廣告時是一樣的。問題是,現在,按鈕丟失..

enter image description here

回答

2

更改頂層相對佈局的線性佈局(垂直),然後在使用layout_weight三種佈局。將mytouchview的layout_weight設置爲1,將另外兩個設置爲0.這將爲mytouchview提供所有額外的空間,並將按鈕和廣告推到底部。當廣告佔據空間時,會適當地推動按鈕托盤,但如果廣告從未加載過,則不會佔用任何空間。

+0

謝謝。有效 :) – rootpanthera

1

嘗試一個:

<?xml version="1.0" encoding="utf-8"?> 
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" xmlns:app="http://schemas.android.com/apk/res/example.com"> 

<LinearLayout 
    android:layout_height="match_parent" 
    android:layout_width="match_parent" 
    android:layout_above="@+id/myAdView" 
    android:orientation="vertical" > 


    <com.example.touch.TouchImageView android:id="@+id/mytouchview" 
     android:layout_height="match_parent" 
     android:layout_width="match_parent" 
     android:layout_marginLeft="5dp" 
     android:layout_marginRight="5dp" 
     android:layout_marginTop="5dp" 
     /> 

    <RelativeLayout 
     android:id="@id/+relat" 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:paddingLeft="10dp" 
     android:paddingRight="10dp" 
     > 

     <ImageButton android:layout_width="wrap_content" android:layout_height="wrap_content" android:padding="3dp" android:layout_alignParentLeft="true" 
     android:background="@null" android:src="@drawable/previous" android:id="@+id/previous"/> 

     <TextView android:layout_height="wrap_content" android:layout_width="wrap_content" android:textSize="20sp" android:text="2/15" 
      android:id="@+id/memeNumber" android:layout_centerInParent="true" android:layout_margin="5dp"/> 


     <ImageButton android:layout_width="wrap_content" android:layout_height="wrap_content" android:padding="3dp" android:layout_alignParentRight="true" 
     android:background="@null" android:src="@drawable/next" android:id="@+id/next"/> 


    </RelativeLayout> 

</LinearLayout> 

<com.csjy.sfwn148282.AdView 
    xmlns:ap="http://schemas.android.com/apk/res-auto" 
    android:id="@id/myAdView" 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    ap:animation="fade" 
    ap:placementType="interstitial" 
    ap:banner_type="inappad" 
    ap:test_mode="true" 
    ap:canShowMR="false" 
    android:layout_alignParentBottom="true" 
/> 
</RelativeLayout> 
+0

該XML有些問題。文檔有2個視圖?線性和AdView。這是正確的嗎?因爲我遇到了XML錯誤:「在根元素之後的文檔中的標記必須格式良好。」還有2. relativeLayout結束標籤,並且只有1個線性佈局開始標籤。 – rootpanthera

+0

對不起,你是對的。我修正了這一點。 – Szymon

+0

沒問題。但是我仍然遇到xml錯誤:「根元素後面的文檔中的標記必須格式良好。」可能是因爲文檔有兩個子視圖。這甚至允許嗎? (在「AdView」開始的地方行) – rootpanthera