2012-09-26 40 views
8

我試圖找出一種方法來對齊佈局中的項目相對於包含的佈局中的項目。

這裏有一個直觀表示: enter image description herelayout_below項目裏面包含的佈局

這裏就是我要找的(這顯然是行不通的)示例代碼:
main.xml中

<?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" > 
    <include 
     android:id="@+id/info" 
     android:layout_width="fill_parent" 
     android:layout_height="wrap_content" 
     layout="@layout/info" /> 
    //This would be the dark grey box 
    <RelativeLayout 
     android:layout_below="@id/item1"> 
    </RelativeLayout> 
</RelativeLayout> 

included.xml

<?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="50dp"> 
    <ImageView 
     android:id="@+id/item1" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:layout_centerHorizontal="true" 
     android:layout_centerVertical="true" 
     android:paddingLeft="100dp"/> 
</RelativeLayout> 



我假設來完成,這將是通過動態定位深灰色框代碼的最佳方式,但我不知道從哪裏開始。任何幫助都是極好的。

+0

你不能做你想做的(從我的角度來看,你不會想這樣做)。看看在代碼中添加額外的窗口。 – Luksprog

+0

所以這個解決方案爲我工作https://stackoverflow.com/a/45450305/563735 –

+0

所以這個解決方案已經爲我工作。 https://stackoverflow.com/a/45450305/563735 –

回答

7

你可以在你的包括下面嗎?像這樣的東西(而不是物品1使用信息):

<?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" > 
    <include 
     android:id="@+id/info" 
     android:layout_width="fill_parent" 
     android:layout_height="wrap_content" 
     layout="@layout/info" /> 
    //This would be the dark grey box 
    <RelativeLayout 
     android:layout_below="@id/info"> 
    </RelativeLayout> 
</RelativeLayout> 
+0

我可以,我猜。我原本希望從暗灰色方框中的箭頭指向包含的佈局內的元素。如果我採納你的建議,我只需要移除箭頭,這就暗示它與盒子相配。儘管如此,我真的正在尋找一種方法將其與包含的佈局內的東西對齊。在包含的元素中會有幾個項目,我希望「彈出」對齊到哪個項目被點擊。我更新了圖像,以更清晰地瞭解我正在努力完成的任務。 – Rawr

+0

我想我已經決定走這個方向,所以我接受這個答案:) – Rawr