gpt4 book ai didi

android - 在页面底部添加一个不重叠内容的 Admob 横幅

转载 作者:行者123 更新时间:2023-11-30 02:52:10 27 4
gpt4 key购买 nike

我想在页面底部安装一个横幅,但它与主屏幕的内容重叠。在主屏幕中有很多内容并且有滚动。

有人知道为什么吗?谢谢。

XML

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:androidsam="http://schemas.android.com/apk/res/com.jameselsey"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >

<LinearLayout
android:id="@+id/home_layout"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="vertical" >

<LinearLayout <!-- CONTENT LAYOUT HERE -->

android:id="@+id/flContainer"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="vertical" >
</LinearLayout>
<!-- Put all your application views here, such as buttons, textviews, edittexts and so on -->

</LinearLayout>

<LinearLayout
android:id="@+id/ad_layout" <!-- AdMob LAYOUT -->
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_alignBottom="@+id/home_layout"
android:layout_alignParentBottom="true"
android:gravity="bottom"
android:orientation="vertical" >
</LinearLayout>

</RelativeLayout>

主 Activity .java

// Create an ad.
adView = new AdView(context);
adView.setAdSize(AdSize.BANNER);
adView.setAdUnitId(AD_UNIT_ID);

// Add the AdView to the view hierarchy. The view
// will have no size
// until the ad is loaded.
LinearLayout layout = (LinearLayout) findViewById(R.id.ad_layout);
layout.getBottom();
layout.addView(adView);

// Create an ad request. Check logcat output for the
// hashed device ID to
// get test ads on a physical device.
AdRequest adRequest = new AdRequest.Builder()
.addTestDevice(AdRequest.DEVICE_ID_EMULATOR)
.addTestDevice("INSERT_YOUR_HASHED_DEVICE_ID_HERE").build();

// Start loading the ad in the background.
adView.loadAd(adRequest);

最佳答案

您可以使用相对定位来解决它,例如尝试将 above 属性设置为您的 home_layout。-

<LinearLayout
android:id="@+id/home_layout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_above="@+id/ad_layout"
android:orientation="vertical" >

编辑

此外,您需要从 ad_layout 中删除属性 layout_alignBottom

android:layout_alignBottom="@+id/home_layout"

编辑 2

这里有一个基本示例来说明您的场景。-

<?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" >

<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@color/green"
android:layout_above="@+id/banner" />

<LinearLayout
android:id="@+id/banner"
android:layout_width="match_parent"
android:layout_alignParentBottom="true"
android:layout_height="200dp"
android:orientation="vertical"
android:background="@color/gray" />
</RelativeLayout>

这导致.-

enter image description here

另一种方法是将根 RelativeLayout 更改为垂直 LinearLayout,说到这一点,如果您坚持使用 RelativeLayout,您应该删除 orientation 属性。

关于android - 在页面底部添加一个不重叠内容的 Admob 横幅,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23969452/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com