1

我有一个ViewPagerwith a PagerTitleStripwhich hasMATCH_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>
4

1 回答 1

4

在您的布局 XML res 文件中,在 MATCH_PARENT 视图中添加此属性android:layout_above。并在其值中给出广告横幅的 id。现在您的 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>
于 2016-08-15T11:58:58.953 回答