2012-09-26 41 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