Android:将广告放置在屏幕底部

时间:2014-11-19 06:43:01

标签: android android-layout listview

我想在屏幕底部放置广告横幅。我编写了以下代码,其中有一个错误,即当广告覆盖内容时listview内容过大,并且listview的最后一个元素永远不可见。我如何编码,以便每当广告不可见时(由于任何原因),listview应占据整个屏幕,每当广告可见时,它们不应覆盖列表视图的最后一个元素。

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:id="@+id/rlLayout"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:background="@drawable/background_img"
    tools:context="${packageName}.${activityClass}" >

    <LinearLayout
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentTop="true" >

        <ListView
            android:id="@+id/rhymesList"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:divider="@null"
            android:dividerHeight="0dp" >
        </ListView>
    </LinearLayout>

    <com.startapp.android.publish.banner.Banner
        android:id="@+id/startAppBanner"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentBottom="true"
        android:layout_centerHorizontal="true" />

</RelativeLayout>

4 个答案:

答案 0 :(得分:3)

在线性布局中添加以下内容

android:layout_above="@+id/startAppBanner"

它肯定会起作用。

答案 1 :(得分:2)

尝试使用此代码

    <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
        xmlns:tools="http://schemas.android.com/tools"
        android:id="@+id/rlLayout"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:background="@drawable/background_img"
        tools:context="${packageName}.${activityClass}" >

        <com.startapp.android.publish.banner.Banner
            android:id="@+id/startAppBanner"
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:layout_alignParentBottom="true"
            android:layout_centerHorizontal="true" />

        <ListView
            android:id="@+id/rhymesList"
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:layout_above="@+id/startAppBanner"
            android:divider="@null"
            android:dividerHeight="0dp" >
        </ListView>



    </RelativeLayout>

答案 2 :(得分:1)

您可以将“layout_above”设置为“startAppBanner”,希望能够实现这一目标

答案 3 :(得分:0)

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:id="@+id/rlLayout"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:background="@drawable/button"
    android:orientation="vertical"
    tools:context="${packageName}.${activityClass}" >

    <ListView
        android:id="@+id/rhymesList"
        android:layout_width="match_parent"
        android:layout_weight="1"
        android:layout_height="0dp"
        android:divider="@null"
        android:dividerHeight="0dp" >
    </ListView>

    <com.startapp.android.publish.banner.Banner
        android:id="@+id/startAppBanner"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"/>
</LinearLayout>