我試圖將TextView dependent
置於RelativeLayout內的其他TextView anchor
之上,但我無法設法使dependent
得到顯示。RelativeLayout:如果涉及保證金,則不能在視圖上方分配視圖
現狀:
的anchor
將與家長的頂部對齊+一些marginTop使其更父(RelativeLayout的)的中心,和dependent
將對齊是上述的這anchor
。
這是行不通的;當我將它分配到anchor
以上時,似乎android假定anchor
的頂部是父級的頂部,並在屏幕之外(在其上方)繪製dependent
。
這不應該是這樣,因爲我使用的保證金代替填充所以RelativeLayout的頂部和anchor
之間的區域不應該是anchor
本身的一部分(我檢查與層次結構的大小觀衆)。或者,也許我錯了? :S
這是一個簡單的佈局代碼:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
>
<TextView android:id="@+id/anchor"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:layout_marginTop="100px"
android:text="Anchor point."
/>
<TextView android:id="@+id/dependent"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_above="@id/anchor"
android:text="Dependent."
/>
</RelativeLayout>
期望:
------------- | | |dependent | |anchor | | | -------------
發生了什麼事:
dependent (out of screen display) ------------- | | | | |anchor | | | -------------
希望:
有人可以幫我嗎?或者,也許可以幫助指出我是否犯了一個錯誤。我需要在我的真實實現中使用RelativeLayout(以上只是一個示例)。
在此先感謝。
你有沒有想過這個?我遇到了同樣的問題 –
對不起,我沒有注意到你的評論。不,我不知道這裏出了什麼問題。最後,我用一個空洞的視圖作爲填充來替換錨的邊緣。 –
是的,我最終從另一個視圖的底部保留底部 –