附加到底部的 AdView 不允许我在 Recyclerview 中看到最后一项
AdView attached to bottom doesn't let me see last item in Recyclerview
我有一个 RelativeLayout
,里面有一个 RecyclerView
和一个 LinearLayout
,里面有一个 AdView
。 RecyclerView
有很多项目,当我无法在屏幕上显示它们时,我只需要向下滚动才能看到它们,但现在我添加了附加到屏幕底部的 LinearLayout
AdView
在里面,我向下滚动,但看不到 RecyclerView
的最后一项。我将 LinearLayout
附加到底部,但它似乎在 RecyclerView
上方,我希望 RecyclerView
在屏幕中显示项目,但不在 LinearLayout
后面。可能吗?
这是我的 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:ads="http://schemas.android.com/apk/res-auto">
<android.support.v7.widget.RecyclerView
android:id="@+id/rvGeneric"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:scrollbars="vertical">
</android.support.v7.widget.RecyclerView>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:gravity="center">
<com.google.android.gms.ads.AdView
android:id="@+id/adViewBaseRefresh"
android:layout_width="fill_parent"
android:layout_height="53dp"
ads:adSize="BANNER"
ads:adUnitId="@string/banner_ad_unit_id"
android:layout_marginBottom="3dp">
</com.google.android.gms.ads.AdView>
</LinearLayout>
相对布局需要 "Relative" 在 XML 中定义的关系。因为你没有任何东西(除了对齐底部的线性布局),结果是 LL 和 RecyclerView 重叠。
将行 android:layout_below="@id/rvGeneric" 添加到线性布局
<?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:ads="http://schemas.android.com/apk/res-auto">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="@+id/ll_ad"
android:layout_alignParentBottom="true"
android:gravity="center">
<com.google.android.gms.ads.AdView
android:id="@+id/adViewBaseRefresh"
android:layout_width="fill_parent"
android:layout_height="53dp"
ads:adSize="BANNER"
ads:adUnitId="@string/banner_ad_unit_id"
android:layout_marginBottom="3dp">
</com.google.android.gms.ads.AdView>
</LinearLayout>
<android.support.v7.widget.RecyclerView
android:id="@+id/rvGeneric"
android:layout_above="@id/ll_ad"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:scrollbars="vertical"/>
</RelativeLayout>
为此,我个人会使用如下所示的 LinearLayout:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
xmlns:ads="http://schemas.android.com/apk/res-auto"
tools:context="com.example.geoff.Whosebugtesting.MainActivity"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<ScrollView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:paddingBottom="@dimen/activity_vertical_margin"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content">
<TextView
android:id="@+id/rvGeneric"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:text="TESTING2"
android:background="#FFF000"
android:textSize="200dp"
android:scrollbars="vertical">
</TextView>
</LinearLayout>
</ScrollView>
<TextView
android:id="@+id/adViewBaseRefresh"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="TESTING"
android:textSize="30dp"
android:textColor="#FFF000"
android:background="#000000"
android:layout_marginBottom="3dp"
android:layout_weight="0.1">
</TextView>
</LinearLayout>
如果您特别想使用 RelativeLayout 那么:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
xmlns:ads="http://schemas.android.com/apk/res-auto"
tools:context="com.gfaiers.layoutexamples.MainActivity"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<ScrollView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:paddingBottom="@dimen/activity_vertical_margin"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<android.support.v7.widget.RecyclerView
android:id="@+id/rvGeneric"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:scrollbars="vertical">
</android.support.v7.widget.RecyclerView>
</LinearLayout>
</ScrollView>
<com.google.android.gms.ads.AdView
android:id="@+id/adViewBaseRefresh"
android:layout_width="match_parent"
android:layout_height="wrap_content"
ads:adSize="BANNER"
ads:adUnitId="@string/banner_ad_unit_id"
android:layout_marginBottom="3dp">
</com.google.android.gms.ads.AdView>
</RelativeLayout>
我有一个 RelativeLayout
,里面有一个 RecyclerView
和一个 LinearLayout
,里面有一个 AdView
。 RecyclerView
有很多项目,当我无法在屏幕上显示它们时,我只需要向下滚动才能看到它们,但现在我添加了附加到屏幕底部的 LinearLayout
AdView
在里面,我向下滚动,但看不到 RecyclerView
的最后一项。我将 LinearLayout
附加到底部,但它似乎在 RecyclerView
上方,我希望 RecyclerView
在屏幕中显示项目,但不在 LinearLayout
后面。可能吗?
这是我的 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:ads="http://schemas.android.com/apk/res-auto">
<android.support.v7.widget.RecyclerView
android:id="@+id/rvGeneric"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:scrollbars="vertical">
</android.support.v7.widget.RecyclerView>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:gravity="center">
<com.google.android.gms.ads.AdView
android:id="@+id/adViewBaseRefresh"
android:layout_width="fill_parent"
android:layout_height="53dp"
ads:adSize="BANNER"
ads:adUnitId="@string/banner_ad_unit_id"
android:layout_marginBottom="3dp">
</com.google.android.gms.ads.AdView>
</LinearLayout>
相对布局需要 "Relative" 在 XML 中定义的关系。因为你没有任何东西(除了对齐底部的线性布局),结果是 LL 和 RecyclerView 重叠。
将行 android:layout_below="@id/rvGeneric" 添加到线性布局
<?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:ads="http://schemas.android.com/apk/res-auto">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="@+id/ll_ad"
android:layout_alignParentBottom="true"
android:gravity="center">
<com.google.android.gms.ads.AdView
android:id="@+id/adViewBaseRefresh"
android:layout_width="fill_parent"
android:layout_height="53dp"
ads:adSize="BANNER"
ads:adUnitId="@string/banner_ad_unit_id"
android:layout_marginBottom="3dp">
</com.google.android.gms.ads.AdView>
</LinearLayout>
<android.support.v7.widget.RecyclerView
android:id="@+id/rvGeneric"
android:layout_above="@id/ll_ad"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:scrollbars="vertical"/>
</RelativeLayout>
为此,我个人会使用如下所示的 LinearLayout:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
xmlns:ads="http://schemas.android.com/apk/res-auto"
tools:context="com.example.geoff.Whosebugtesting.MainActivity"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<ScrollView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:paddingBottom="@dimen/activity_vertical_margin"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content">
<TextView
android:id="@+id/rvGeneric"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:text="TESTING2"
android:background="#FFF000"
android:textSize="200dp"
android:scrollbars="vertical">
</TextView>
</LinearLayout>
</ScrollView>
<TextView
android:id="@+id/adViewBaseRefresh"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="TESTING"
android:textSize="30dp"
android:textColor="#FFF000"
android:background="#000000"
android:layout_marginBottom="3dp"
android:layout_weight="0.1">
</TextView>
</LinearLayout>
如果您特别想使用 RelativeLayout 那么:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
xmlns:ads="http://schemas.android.com/apk/res-auto"
tools:context="com.gfaiers.layoutexamples.MainActivity"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<ScrollView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:paddingBottom="@dimen/activity_vertical_margin"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<android.support.v7.widget.RecyclerView
android:id="@+id/rvGeneric"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:scrollbars="vertical">
</android.support.v7.widget.RecyclerView>
</LinearLayout>
</ScrollView>
<com.google.android.gms.ads.AdView
android:id="@+id/adViewBaseRefresh"
android:layout_width="match_parent"
android:layout_height="wrap_content"
ads:adSize="BANNER"
ads:adUnitId="@string/banner_ad_unit_id"
android:layout_marginBottom="3dp">
</com.google.android.gms.ads.AdView>
</RelativeLayout>