1

我有一個ViewPagerPagerTitleStrip它有MATCH_PARENT高度。頁面只有一個文本,但有些頁面有垂直滾動,因爲文本很長。如何將AdMob橫幅放在MATCH_PARENT高度的視圖下方?

現在我試圖找到將AdMob橫幅放在佈局底部的最佳策略。這是情況: - 如果我放在ViewPager以下,橫幅不可見,因爲ViewPagerMATCH_PARENT。 - 如果我放置在佈局的底部,那麼ViewPager正在從橫幅後面滾動內容,這不是正確的行爲。

可以制定一條規則,使橫幅停留在ViewPager以下,但不使滾動內容的ViewPager位於橫幅後面?

謝謝

的辦法,我想補充的旗幟:

RelativeLayout.LayoutParams adsParams = new RelativeLayout.LayoutParams(LinearLayout.LayoutParams.MATCH_PARENT, LinearLayout.LayoutParams.WRAP_CONTENT); 
     adsParams.addRule(RelativeLayout.ALIGN_PARENT_BOTTOM); 
     adsParams.addRule(RelativeLayout.BELOW,R.id.pager); 
     if (AdManager.getInstance().getAdView()!=null){ 
      View view = AdManager.getInstance().getAdView(); 
      mainLayout.addView(view, adsParams); 
     } 

我的佈局:

<android.support.v4.widget.DrawerLayout 
    xmlns:android="http://schemas.android.com/apk/res/android" 
    xmlns:app="http://schemas.android.com/apk/res-auto" 
    android:id="@+id/drawer_layout" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent"> 
    <!-- The main content view --> 
    <RelativeLayout 
     android:id="@+id/main_layout" 
     android:layout_width="match_parent" 
     android:layout_height="match_parent"> 
     <android.support.v4.view.ViewPager 
      xmlns:android="http://schemas.android.com/apk/res/android" 
      android:id="@+id/pager" 
      android:layout_width="match_parent" 
      android:layout_height="match_parent"> 

      <android.support.v4.view.PagerTitleStrip 
       android:id="@+id/pager_title_strip" 
       android:layout_width="match_parent" 
       android:layout_height="wrap_content" 
       android:layout_gravity="top" 
       android:paddingTop="4dp" 
       android:paddingBottom="4dp" 
       style="@style/CustomPagerTitleStrip"/> 
     </android.support.v4.view.ViewPager> 
    </RelativeLayout> 
    <!-- The navigation drawer --> 
    <android.support.design.widget.NavigationView 
     android:id="@+id/navigation_view" 
     android:layout_width="wrap_content" 
     android:layout_height="match_parent" 
     android:layout_gravity="start" 
     android:fitsSystemWindows="true" 
     app:headerLayout="@layout/drawer_header" 
     app:menu="@menu/drawer_menu" 
     style="@style/NavigationDrawerStyle"/> 
</android.support.v4.widget.DrawerLayout> 
+0

你就不能換了'ViewPager'和旗幟在佈局,說'LinearLayout'和堆棧他們彼此頂部?這樣你就不會有任何內容重疊。 –

回答

2

在您的佈局XML資源文件中MATCH_PARENT添加此屬性android:layout_above視圖。並以其價值爲廣告橫幅標識。現在,您的看法match_parent將廣告橫幅上面

<?xml version="1.0" encoding="utf-8"?> 
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    android:orientation="vertical" android:layout_width="match_parent" 
    android:layout_height="match_parent"> 
    <RelativeLayout 
     android:layout_width="match_parent" 
     android:layout_above="@+id/temp" 
     android:layout_height="match_parent"></RelativeLayout> 
    <View 
     android:id="@+id/temp" 
     android:layout_alignParentBottom="true" 
     android:layout_width="match_parent" 
     android:layout_height="60dp"/> 

</RelativeLayout> 
+0

爲什麼如果我把以上的作品,如果我把下面的橫幅視圖不工作?令人困惑 – NullPointerException

+0

Layout_above表示此match_parent視圖應位於指定的廣告橫幅視圖之上。 –

+0

是的,但layout_below是相反的,並且如果我放在橫幅視圖上,它應該是工作的,這是必須在另一個下方的視圖。不工作。爲什麼? – NullPointerException