gpt4 book ai didi

安卓用户界面 : align a fragment above another fragment that is aligned bottom

转载 作者:行者123 更新时间:2023-11-29 01:30:07 28 4
gpt4 key购买 nike

我已经一年多没有为 Android 开发了,我对它有点生疏了。我正在尝试设置一个有点简单的 UI:屏幕底部的底部栏和它上面的 fragment (但没有填充整个高度)。像这样:

enter image description here

我认为这会很简单,但经过一段时间的努力之后,我无法在没有一些“技巧”的情况下让它工作。

底部栏也作为 Fragment 实现。这是我的 XML:

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >

<fragment
android:id="@+id/bottomBar"
android:name="com.mytestpackage.BottomBarFragment"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true" />

<FrameLayout
android:id="@+id/fragmentContainer"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_above="@id/bottomBar"
android:layout_alignParentBottom="true" />

</RelativeLayout>

fragmentContainer 中的Fragment 是从代码中动态加载的。使用上面的代码粘贴,fragmentContainer 与底部对齐,但它不在底部栏上方,它们是重叠的。如果我从 fragmentContainer 中移除 alignParentBottom,它就会被放置在屏幕的顶部。

就像我说的,我找到了两个“黑客”来解决它,但我不太喜欢它们:

1- 为 fragmentContainer 设置一个 padding/margin 底部。2- 在屏幕顶部使用填充空布局并将 fragmentContainer 设置在该布局下方。

有没有什么方法可以实现我想要的布局,而不必像我说的那样使用一些技巧?

谢谢!

最佳答案

添加到相对布局:

android:gravity="bottom"

啊,android:orientation="vertical"RelativeLayout 没有意义

一个更简单的解决方案是使用垂直方向和重力底部的 LinearLayout 而不是 RelativeLayout

关于安卓用户界面 : align a fragment above another fragment that is aligned bottom,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31686741/

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