8

I'm trying to figure out a way to align an item in a layout in respect to an item within an included layout.

Here's a visual representation: enter image description here

And here is example code that I'm looking for (which obviously doesn't work):
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>



I'm assuming the best way to accomplish this would be through dynamically positioning the dark grey box in code, but I have no idea where to start. Any help would be awesome.

Rawr
  • 2,206
  • 3
  • 25
  • 53

1 Answers1

7

Can you make this below your include? Something like this (instead item1 use info):

<?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>
Yury
  • 20,618
  • 7
  • 58
  • 86
  • I could, I guess. I originally wanted to have an arrow from the dark grey box point to the element inside the included layout. If I take your suggestion, I'd just have to remove the arrow and it would be sort of implied that it matched up with the box. I'm really looking for a method to align it to something inside an included layout though. The there will be several items inside the included element, and I would like the "popup" to align to whichever item is clicked. I updated the image to give a clearer idea of what I'm trying to accomplish. – Rawr Sep 26 '12 at 11:02
  • I think I've decided to go in this direction, so I'm accepting this answer :) – Rawr Sep 26 '12 at 16:43