gpt4 book ai didi

Android,在屏幕底部定位一个元素,固定

转载 作者:行者123 更新时间:2023-11-29 16:02:17 29 4
gpt4 key购买 nike

我试图通过将 fragment 注入(inject)容器来在每个屏幕的底部放置一个广告 View 。通过使用 LinearLayout,我可以将 adview 置于操作栏下方的顶部。我已经尝试了 RelativeLayout 的各种组合,但似乎没有一个能使调整方向的 adview 保持不变。

这是适用于顶部的布局:

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/fragmentContainer"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
xmlns:ads="http://schemas.android.com/apk/res-auto"
>

<com.google.android.gms.ads.AdView android:id="@+id/adView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
ads:adSize="SMART_BANNER"/>
</LinearLayout>

然后我将 fragment 添加到 fragmentContainer。如何使 adview 静态定位在屏幕底部?我尝试了各种布局嵌套策略,但到目前为止都没有奏效。

横幅不应覆盖或切断 fragment 的任何部分。

最佳答案

带有 alignParentBottom 属性的 RelativeLayout 怎么样?此外,在 FrameLayout 之外的另一个 View 组中添加 fragment 也不是一个好习惯。这不会卡住或破坏您的 Activity ,但它可能会提供一些错误。像这样的东西应该可以解决问题:

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

<com.google.android.gms.ads.AdView
android:layout_alignParentBottom="true"
android:id="@+id/adView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
ads:adSize="SMART_BANNER" />

<FrameLayout
android:id="@+id/fragmentContainer"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_above="@id/adView" />

</RelativeLayout>

希望这对您有所帮助。

关于Android,在屏幕底部定位一个元素,固定,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23153654/

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