[英]Android UI: align a fragment above another fragment that is aligned bottom
我已经一年多没有为Android
开发了,我对它有点生疏了。 我正在尝试设置一个有点简单的UI
:屏幕底部的底部栏和其上方的片段(但没有填充整个高度)。 像这样的东西:
我认为这会很简单,但经过一段时间的努力,我无法在没有一些“黑客”的情况下使其工作。
底部栏也实现为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>
Fragment
中的Fragment
是从代码动态加载的。 使用上面的代码粘贴,fragmentContainer 与底部对齐但它不在底部栏上方,它们是重叠的。 如果我从 fragmentContainer 中移除alignParentBottom
,那么它就会被放置在屏幕的顶部。
就像我说的,我找到了两个“黑客”来解决它,但我不太喜欢它们:
1- 为 fragmentContainer 设置padding
/ margin
底部。 2- 在屏幕顶部使用填充空布局并将 fragmentContainer 设置为低于该布局。
有没有什么方法可以实现我想要的布局,而不必使用我说的那些技巧?
谢谢!
添加到相对布局:
android:gravity="bottom"
啊, android:orientation="vertical"
对RelativeLayout
来说毫无意义
一个更简单的解决方案是使用具有垂直方向和重力底部的LinearLayout
而不是RelativeLayout
。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.