Account Options

  1. Sign in
The old Google Groups will be going away soon, but your browser is incompatible with the new version.
Google Groups Home
« Groups Home
RelativeLayout in ListView item
There are currently too many topics in this group that display first. To make this topic appear first, remove this option from another topic.
There was an error processing your request. Please try again.
flag
  6 messages - Collapse all  -  Translate all to Translated (View all originals)
The group you are posting to is a Usenet group. Messages posted to this group will make your email address visible to anyone on the Internet.
Your reply message has not been sent.
Your post was successful
 
From:
To:
Cc:
Followup To:
Add Cc | Add Followup-to | Edit Subject
Subject:
Validation:
For verification purposes please type the characters you see in the picture below or the numbers you hear by clicking the accessibility icon. Listen and type the numbers you hear
 
Spencer Riddering  
View profile  
 More options Sep 1 2008, 1:38 pm
From: Spencer Riddering <ponderyon...@gmail.com>
Date: Mon, 1 Sep 2008 10:38:11 -0700 (PDT)
Local: Mon, Sep 1 2008 1:38 pm
Subject: RelativeLayout in ListView item
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);
        }

}

relative_layout_in_list_item.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="wrap_content"
        >
        <TextView
            android:layout_centerVertical="true"
                android:layout_alignParentLeft="true"
                android:text="Left Center"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content">
        </TextView>
        <LinearLayout
            android:layout_centerInParent="true"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:orientation="vertical">
                <TextView
                        android:text="Upper"
                        android:layout_width="wrap_content"
                        android:layout_height="wrap_content">
                </TextView>
                <TextView
                        android:text="Lower"
                        android:layout_width="wrap_content"
                        android:layout_height="wrap_content">
                </TextView>
        </LinearLayout>
</RelativeLayout>

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?


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Mark Murphy  
View profile  
 More options Sep 1 2008, 1:53 pm
From: Mark Murphy <mmur...@commonsware.com>
Date: Mon, 01 Sep 2008 13:53:28 -0400
Local: Mon, Sep 1 2008 1:53 pm
Subject: Re: [android-developers] RelativeLayout in ListView item

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


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Spencer Riddering  
View profile  
 More options Sep 2 2008, 12:59 am
From: Spencer Riddering <ponderyon...@gmail.com>
Date: Mon, 1 Sep 2008 21:59:57 -0700 (PDT)
Local: Tues, Sep 2 2008 12:59 am
Subject: Re: RelativeLayout in ListView item
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.

 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Mark Murphy  
View profile  
 More options Sep 2 2008, 7:59 am
From: Mark Murphy <mmur...@commonsware.com>
Date: Tue, 02 Sep 2008 07:59:37 -0400
Local: Tues, Sep 2 2008 7:59 am
Subject: Re: [android-developers] Re: RelativeLayout in ListView item

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!


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Mark Murphy  
View profile  
 More options Sep 2 2008, 10:20 am
From: Mark Murphy <mmur...@commonsware.com>
Date: Tue, 02 Sep 2008 10:20:02 -0400
Local: Tues, Sep 2 2008 10:20 am
Subject: Re: [android-developers] Re: RelativeLayout in ListView item

Spencer Riddering wrote:
> You seem to have missed the problem entirely. Please compile next
> time.

I did you one better. I wrote up a whole blog post on my diagnostic steps:

http://androidguys.com/2008/09/02/diagnosing-layout-problems/

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!


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Spencer Riddering  
View profile  
 More options Sep 2 2008, 2:11 pm
From: Spencer Riddering <ponderyon...@gmail.com>
Date: Tue, 2 Sep 2008 11:11:14 -0700 (PDT)
Local: Tues, Sep 2 2008 2:11 pm
Subject: Re: RelativeLayout in ListView item
Hi Mark,

Thanks, I really like your post.

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.

Spencer Riddering

<?xml version="1.0" encoding="utf-8"?>
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/
android"
     android:layout_width="fill_parent"
     android:layout_height="wrap_content"
     >
     <TextView
         android:text="Left Center"
         android:layout_width="wrap_content"
         android:layout_height="wrap_content"
         android:layout_gravity="center_vertical"
     />
     <LinearLayout
         android:layout_width="fill_parent"
         android:layout_height="wrap_content"
         android:orientation="vertical"
         android:layout_gravity="center"
         >
         <TextView
             android:text="Upper"
             android:layout_width="wrap_content"
             android:layout_height="wrap_content"
             android:layout_gravity="center_horizontal"
             android:layout_weight="1"
         />
         <TextView
             android:text="Lower"
             android:layout_width="wrap_content"
             android:layout_height="wrap_content"
             android:layout_gravity="center_horizontal"
             android:layout_weight="1"
         />
     </LinearLayout>
</FrameLayout>

On Sep 2, 10:20 pm, Mark Murphy <mmur...@commonsware.com> wrote:

http://spencer.riddering.net

 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
End of messages
« Back to Discussions « Newer topic     Older topic »