在底部显示广告而不重叠列表视图

Boa*_*rdy 5 android admob android-layout

我正在研究android项目,我遇到一个问题,在列表视图下方的屏幕底部显示广告而不会导致任何重叠.

目前,如果列表视图中存在大量项目导致滚动,则广告应该显示在列表视图下方,但是当广告位于列表视图的顶部时,因此,用户可以'看看列表视图底部的内容.

下面是我的XML布局的副本

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:ads="http://schemas.android.com/apk/lib/com.google.ads"
    android:layout_width="match_parent"
    android:layout_height="fill_parent"
    android:background="@color/black"
    android:orientation="vertical" >
    <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:orientation="horizontal">
    <TextView android:id="@+id/password_noRecords"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:gravity="center"
        android:layout_gravity="center"
        android:text="There are currently\nno saved logins"
        android:textSize="20dp"
        android:textStyle="bold|italic"/>
    <ListView 
        android:id="@android:id/list"
        android:layout_width="fill_parent"
        android:layout_height="fill_parent">
    </ListView>
    <Button android:id="@+id/password_clearSearch" 
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:text="@string/password_clear_search"
        android:layout_alignParentBottom="true"
        android:visibility="gone"/>
    </LinearLayout>
    <com.google.ads.AdView android:id="@+id/adView"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:layout_gravity="center_horizontal"
        android:layout_alignParentBottom="true"
        android:gravity="center_horizontal"
        ads:adUnitId="a14d6125d95c70b"
        ads:adSize="BANNER"
        ads:testDevices="TEST_EMULATOR, 015d1884222bfe01"/>
</RelativeLayout>
Run Code Online (Sandbox Code Playgroud)

我有很多不同的方法,将它全部放在相对布局中而不是具有另一个线性布局,没有对齐父底部= true但是它位于列表视图的顶部,重叠列表视图顶部的任何内容.

感谢您的任何帮助,您可以提供.

Ral*_*gha 12

您可以通过仅使用a LinearLayout作为基础(摆脱RelativeLayout)并使用android:layout_weight您的属性来解决此问题ListView.例:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical">
    <TextView android:id="@+id/password_noRecords"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:gravity="center"
        android:layout_gravity="center"
        android:text="There are currently\nno saved logins"
        android:textSize="20dp"
        android:textStyle="bold|italic"/>
    <ListView 
        android:id="@android:id/list"
        android:layout_width="fill_parent"
        android:layout_height="0dp"
        android:layout_weight="1" />
    <Button android:id="@+id/password_clearSearch" 
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:text="@string/password_clear_search"
        android:layout_alignParentBottom="true"
        android:visibility="gone"/>
    <com.google.ads.AdView android:id="@+id/adView"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:layout_gravity="center_horizontal"
        android:gravity="center_horizontal"
        ads:adUnitId="a14d6125d95c70b"
        ads:adSize="BANNER"
        ads:testDevices="TEST_EMULATOR, 015d1884222bfe01"/>
</LinearLayout>
Run Code Online (Sandbox Code Playgroud)

注意ListViewandroid:layout_height="0dp"android:layout_weight="1".这告诉它扩展以填充其他元素放入后留下的任何空间LinearLayout.