0

我有一个布局,其中有一个网格视图,我想在屏幕底部显示横幅广告我有以下代码

<?xml version="1.0" encoding="utf-8"?>
<android.support.design.widget.CoordinatorLayout

    xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:background="@color/backgroundColor"
    android:fitsSystemWindows="true">

    <include layout="@layout/detail_activity_bar"></include>

    <FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        app:layout_behavior="@string/appbar_scrolling_view_behavior">
            <GridView xmlns:android="http://schemas.android.com/apk/res/android"
                android:id="@+id/home_grid"
                android:layout_width="match_parent"
                android:layout_height="match_parent"
                android:horizontalSpacing="5dp"
                android:verticalSpacing="5dp"
                android:layout_marginLeft="5dp"
                android:layout_marginRight="5dp"
                android:layout_marginTop="5dp"
                android:layout_marginBottom="60dp"
                android:numColumns="2"
                android:stretchMode="columnWidth"/>

        <com.google.android.gms.ads.AdView
            xmlns:ads="http://schemas.android.com/apk/res-auto"
            android:id="@+id/adViewGallery"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_centerHorizontal="true"
            android:layout_alignParentBottom="true"
            android:layout_marginBottom="5dp"
            android:layout_gravity="bottom|center"
            ads:adSize="SMART_BANNER"
            ads:adUnitId="@string/home_banner">
        </com.google.android.gms.ads.AdView>
    </FrameLayout>


</android.support.design.widget.CoordinatorLayout>

它适用于 4 英寸移动设备,但在更大的设备上,横幅广告会与网格内容重叠。如何使其适用于所有设备,使其不与应用内容重叠

4

2 回答 2

1

试试下面的布局

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
    android:weightSum="1"
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:background="#29000000"
    android:orientation="vertical"
    android:fitsSystemWindows="true">
    <include layout="@layout/detail_activity_bar"></include>

        <GridView
            android:layout_weight="0.9"
            xmlns:android="http://schemas.android.com/apk/res/android"
            android:id="@+id/home_grid"
            android:layout_width="match_parent"
            android:layout_height="0dp"
            android:horizontalSpacing="5dp"
            android:verticalSpacing="5dp"
            android:layout_marginLeft="5dp"
            android:layout_marginRight="5dp"
            android:layout_marginTop="5dp"
            android:numColumns="2"
            android:stretchMode="columnWidth"/>
        <com.google.android.gms.ads.AdView
            android:layout_weight="0.1"
            xmlns:ads="http://schemas.android.com/apk/res-auto"
            android:id="@+id/adViewGallery"
            android:layout_width="match_parent"
            android:layout_height="0dp"
            android:layout_marginBottom="5dp"
            android:layout_gravity="bottom|center"
            ads:adSize="SMART_BANNER"
            ads:adUnitId="@string/home_banner">
        </com.google.android.gms.ads.AdView>
</LinearLayout>
于 2018-12-08T09:50:26.353 回答
0

只需使用 LinearLayout 或使用 RelativeLayout 而不是 FrameLayout 并且它在所有设备上都是正确的!:)

于 2018-12-08T09:48:16.363 回答