我嘗試在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