我想创建一个如下所示的布局:
(虚线是文本视图的基线。)
所以主锚是大的W,然后abc与W基线对齐,然后def在abc之上。
但是当我为abc设置基线对齐时,def会下降并变得不可见。abc没有问题,它完美对齐。
我找到了使def可见的唯一方法:它正在更改abc的对齐方式,因此它将与W的底部对齐,但这看起来很糟糕,因为较大的字形具有更大的底部边距(基线之间的垂直空间更大和视图的底部边缘)。
看起来基线对齐是以某种特殊方式处理的,因此布局无法计算相关视图的正确位置。
我做错了吗?我的布局有可能吗?
这是 XML:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent" >
<TextView
android:id="@+id/w"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:layout_alignParentTop="true"
android:text="W"
android:textAppearance="?android:attr/textAppearanceLarge"
android:textSize="100sp" />
<TextView
android:id="@+id/abc"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignBaseline="@+id/w"
android:layout_alignParentLeft="true"
android:text="abc"
android:textAppearance="?android:attr/textAppearanceLarge" />
<TextView
android:id="@+id/def"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_above="@+id/abc"
android:layout_alignParentLeft="true"
android:text="def"
android:textAppearance="?android:attr/textAppearanceLarge" />
</RelativeLayout>