如何将 AdMob 横幅放在 MATCH_PARENT 高度的视图下方?
How to put a AdMob banner below a view with MATCH_PARENT height?
我有一个 ViewPager
和一个 PagerTitleStrip
的 MATCH_PARENT
高度。页面只有一段文字,但有些页面因为文字很长,所以有垂直滚动。
现在我正在尝试寻找将 AdMob 横幅广告放在布局底部的最佳策略。是这样的情况:
- 如果我放在 ViewPager
下方,则横幅不可见,因为 ViewPager
有 MATCH_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>
在您的布局 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>
我有一个 ViewPager
和一个 PagerTitleStrip
的 MATCH_PARENT
高度。页面只有一段文字,但有些页面因为文字很长,所以有垂直滚动。
现在我正在尝试寻找将 AdMob 横幅广告放在布局底部的最佳策略。是这样的情况:
- 如果我放在 ViewPager
下方,则横幅不可见,因为 ViewPager
有 MATCH_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>
在您的布局 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>