我有一个 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>
最佳答案
相对布局需要在 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>
关于android - 附加到底部的 AdView 不允许我在 Recyclerview 中看到最后一项,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38130989/