Aligning widget in RelativeLayout with a widget in nested LinearLayout
So I've been looking around for awhile now and can't seem to find an answer to my question
I have tried a few things, but nothing seems to work so I'm wondering if what I'm trying to do is even possible.
Basically I have a RelativeLayout at the base of my XML Layout, and within that RelativeLayout I have some nested LinearLayouts, what I want to do is align a widget in the RelativeLayout to a TextView nested within a LinearLayout, so something like below (unnecessary XML markup has been removed so you can see what I'm trying to do easier)
<RelativeLayout>
<LinearLayout>
<TextView
android:id="@+id/TextView1"/>
<TextView
android:id="@+id/TextView2"/>
</LinearLayout>
<TextView
android:layout_alignLeft="@id/TextView2" />
</RelativeLayout>
At this point I've simply given up attempting to do this and removed the linear layouts from my XML and gone strictly with just the RelativeLayout.
However I'd just like to know if what I originally attempted is possible, and if I wa开发者_如何学Cs just doing it wrong, or because of the way the widget is nested within another layout that it just doesn't work.
Thanks in advance
I'm not sure if this is missing the point (lack of context, but that doesn't matter if I manage to help), but it sounds like you should be able to replace TextView2 with a horizontal LinearLayout containing both TextView2 and the external TextView. But, yes, sticking totally with a RelativeLayout will do a similar thing with more control (I just like nested LinearLayouts, and personally, I'd probably replace the entire RelativeLayout with them, depending on what it's for).
Elements in a RelativeLayout will only align with other elements in the same layout at the same level (siblings).
However, you may be able to achieve something like this with a little work. You could put an ID on the LinearLayout. You could then align the outer TextView with the LinearLayout and use padding and margin attributes (on both TextView2 and the outer TextView) to make it truly line up at display time.
精彩评论