我尝试在RelativeLayout中创建一个半透明的红色视图和一个TextView,其中View的高度遵循TextView的高度,当TextView位于上方时它按预期工作半透明红色景观:android:layout_alignTop不起作用类似于android:layout_alignBottom
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent">
<View
android:background="#FF0000"
android:alpha="0.5"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignBottom="@id/textView"/>
<TextView
android:id="@+id/textView"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="TEST"
android:textSize="50dp"
android:textColor="#000000"/>
</RelativeLayout>
,但我想改变它了一下:把视图TextView的上述和其他利率维持不变,我试图改变android:layout_alignBottom
到android:layout_alignTop
:
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent">
<View
android:background="#FF0000"
android:alpha="0.5"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignTop="@id/textView"/>
<TextView
android:id="@+id/textView"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="TEST"
android:textSize="50dp"
android:textColor="#000000"/>
</RelativeLayout>
但现在看来View
不遵循TextView
高度:
这是什么问题,我该如何解决?
我认为这是不可能由xml完成的。如果您需要将'View'放在'TextView'上方,则无法实现其高度对齐。 – BakaWaii