gpt4 book ai didi

android - layout_above 坏了吗?这个简单的布局让我发疯

转载 作者:行者123 更新时间:2023-11-29 00:13:03 26 4
gpt4 key购买 nike

这是我的代码

<TextView
android:id="@+id/BIG"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="BIG"
android:textSize="50dp" />

<TextView
android:id="@+id/small"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignBaseline="@id/BIG"
android:layout_toRightOf="@id/BIG"
android:text="small"
android:textSize="10dp"

/>

<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_above="@id/small"
android:layout_alignLeft="@id/small"
android:text="small above"
android:textSize="10dp" />

这是我得到的结果(实际截图)。如您所见,整个 TextView 都消失了。

screenshot

这是我想要的结果(在mspaint上编辑)

enter image description here

由于自动填充,我无法使用 align_bottom。这是我使用 align_bottom 而不是 align_Baseline 时的样子(实际屏幕截图)

enter image description here

最佳答案

显然,基线对齐是在所有其他垂直对齐都已执行之后执行的。
因此,“small above”“small” 仍处于默认位置时排在 “small” 上方。然后,“small”与 “BIG” 的基线对齐,将“small above”留在 View 之外,位于 RelativeLayout 的顶部。

这个问题的一个潜在解决方案是将两个较小的 TextView 包装在一个 LinearLayout 中,然后可以将其与左侧较大的 TextView 正确地基线对齐。
并且还将 android:baselineAlignedChildIndex="1" 添加到 LinearLayout,以便第二个 child 的基线与“BIG”对齐

引用:http://scottweber.com/2014/02/06/working-with-baselines-in-relativelayout/

关于android - layout_above 坏了吗?这个简单的布局让我发疯,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28820200/

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