I've been experiencing some problems with the RelativeLayout when it
is used within a ListView item. I've created a simple example of the
problem below.
RelativeLayoutInListItemTest.java
public class RelativeLayoutInListItemTest extends ListActivity {
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
ArrayList<Map<String,String>> al = new
ArrayList<Map<String,String>>();
al.add(new HashMap<String,String>());
al.add(new HashMap<String,String>());
al.add(new HashMap<String,String>());
SimpleAdapter sa = new SimpleAdapter(this, al,
R.layout.relative_layout_in_list_item, new String[]{}, new int[]{});
setListAdapter(sa);
}
Spencer Riddering wrote: > Notice how only the lower half of "Left Center" is displayed. Also, > notice that "Upper" is not displayed.
> Can someone confirm that this is a bug or point out my mistake?
I think the point behind RelativeLayout is for you to be placing widgets relative to other widgets. You're not doing that here, other than your two centering statements. As it stands, your "Left Center" TextView should be overlapping with your LinearLayout on the vertical axis (both are centered), and I have no idea where "Left Center" is supposed to appear on the horizontal axis, since you didn't anchor it to anything or otherwise specify where it is supposed to appear horizontally.
All that being said, I think merely replacing RelativeLayout with a horizontal LinearLayout in your XML will get you the look you want, assuming your TextView labels are accurate vis a vis what you're aiming for.
If you really want to do this with a RelativeLayout, try specifying that your vertical LinearLayout is toRightOf the "Left Center" TextView, and that the "Left Center" TextView is alignParentLeft (so it is flush on the left margin).
Note that my comments are all by a Mark I Eyeball review of your code, as I haven't tried compiling or running it. If this doesn't work, write back with details!
-- Mark Murphy (a Commons Guy) http://commonsware.com Warescription: All titles, revisions, & ebook formats, just $35/year
On Sep 2, 1:53 am, Mark Murphy <mmur...@commonsware.com> wrote:
> Spencer Riddering wrote:
> > Notice how only the lower half of "Left Center" is displayed. Also,
> > notice that "Upper" is not displayed.
> > Can someone confirm that this is a bug or point out my mistake?
> I think the point behind RelativeLayout is for you to be placing widgets
> relative to other widgets. You're not doing that here, other than your
> two centering statements.
Except that I am:
layout_alignParentLeft="true"
and
android:layout_centerInParent="true"
> As it stands, your "Left Center" TextView
> should be overlapping with your LinearLayout on the vertical axis (both
> are centered),
I'm not sure why this is relevant.
> and I have no idea where "Left Center" is supposed to
> appear on the horizontal axis, since you didn't anchor it to anything or
> otherwise specify where it is supposed to appear horizontally.
I did anchor it. Horizontally, "Left Center" is aligned on the
parent's left side:
layout_alignParentLeft="true"
> All that being said, I think merely replacing RelativeLayout with a
> horizontal LinearLayout in your XML will get you the look you want,
> assuming your TextView labels are accurate vis a vis what you're aiming for.
> If you really want to do this with a RelativeLayout, try specifying that
> your vertical LinearLayout is toRightOf the "Left Center" TextView, and
> that the "Left Center" TextView is alignParentLeft (so it is flush on
> the left margin).
> Note that my comments are all by a Mark I Eyeball review of your code,
> as I haven't tried compiling or running it. If this doesn't work, write
> back with details.
You seem to have missed the problem entirely. Please compile next
time.
Spencer Riddering wrote: > On Sep 2, 1:53 am, Mark Murphy <mmur...@commonsware.com> wrote: >> Spencer Riddering wrote: >>> Notice how only the lower half of "Left Center" is displayed. Also, >>> notice that "Upper" is not displayed. >>> Can someone confirm that this is a bug or point out my mistake? >> I think the point behind RelativeLayout is for you to be placing widgets >> relative to other widgets. You're not doing that here, other than your >> two centering statements.
> Except that I am: > layout_alignParentLeft="true" > and > android:layout_centerInParent="true"
Ah, sorry, missed the alignParentLeft in the first one. Damn allergies are making my brain foggy...
> I'm not sure why this is relevant.
Considering you're asking why part of a potentially-overlapping pair of widgets is not displayed, I would think the fact they potentially overlap might be relevant.
> You seem to have missed the problem entirely.
That's likely. My apologies for wasting your time.
-- Mark Murphy (a Commons Guy) http://commonsware.com _The Busy Coder's Guide to Android Development_ Version 1.1 Published!
The upshot is that I fixed the problem with the stacked Upper/Lower TextViews, but I can't figure out what's up with the Left Center one. As I wrote in the post, it could be a bug, or it could be that RelativeLayout is just plain unintuitive to me.
I transcoded the layout into one using pure LinearLayouts at the end, which gets you something that is *almost* what you need.
Sorry that I was unable to completely resolve your issue.
-- Mark Murphy (a Commons Guy) http://commonsware.com _The Busy Coder's Guide to Android Development_ Version 1.1 Published!
I actually started out using LinearLayout but I ran into the same
centering problem that you ended your post on. It was my obsession
with centering "Upper" and "Lower" horizontally across the entire list
item that drove me to RelativeLayout.
I've finally achieved the layout I was looking for, but I had to use
FrameLayout to do it. See below. I'm thinking that TableLayout may
also be suitable but I haven't had time to try it out.
> The upshot is that I fixed the problem with the stacked Upper/Lower
> TextViews, but I can't figure out what's up with the Left Center one. As
> I wrote in the post, it could be a bug, or it could be that
> RelativeLayout is just plain unintuitive to me.
> I transcoded the layout into one using pure LinearLayouts at the end,
> which gets you something that is *almost* what you need.
> Sorry that I was unable to completely resolve your issue.
> --
> Mark Murphy (a Commons Guy)http://commonsware.com > _The Busy Coder's Guide to Android Development_ Version 1.1 Published!