2013-11-27 130 views
1

我有一個簡單的佈局。但我不能讓它與我想放在底部的廣告一起工作。這裏有2個屏幕截圖,有沒有廣告。覆蓋佈局底部的廣告Android

沒有AD

enter image description here

隨着AD

enter image description here

正如你可以看到廣告時,它的加載,它涵蓋了兩個按鈕(這是相對佈局)。我怎樣才能做到這一點,所以當AD加載時,我的相對佈局會在廣告上面「碰撞」?這是我的XML。

<?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"> 



    <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" 
      > 

      <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" 


/> 

</RelativeLayout> 

編輯:

我不喜歡@Szymon勸我,但我現在面臨的問題是,佈局定位就是這樣,直到廣告加載。之後,它就像它應該那樣工作。如何解決這個問題?

enter image description here

回答

2

這會爲你工作。請注意,對於您聲明的每個變量(即使您在除實際元素外的其他位置聲明它),您只應使用@+id一次。在下面的代碼中,它在android:layout_above中聲明,並且僅在實際元素聲明中用作@id

<?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"> 



    <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" 
    /> 

</RelativeLayout> 
+0

它的工作原理。但我現在面臨新的問題。我編輯了我的問題,如果你想看看。 – rootpanthera

+1

如果他已經解決了你的原始問題,那麼答案應該被接受,並開始一個新的問題。如果最初的問題被編輯爲新問題,那麼對於具有相同問題的其他任何人都沒有用。那麼答案沒有任何意義。與已完成的工作相比,它也破壞了獎勵制度。 – Brianjs

+0

@rootpanthera正如Brianjs所說,請另外提問。我會很高興看到它。 – Szymon