Monday, May 3, 2010

Re: [android-developers] RelativeLayout bug ?

It's unfortunately a "working as expected," although I'd agree that
the "expected" is surprising. If you read your layout you will realize
it does not make much sense:

- The container is as tall as its child
- The child is as tall as its content
- You tell the child to center its content (which is meaningless since
both are the same height)
- In the case of RelativeLayout you tell the child to be aligned with
the parent's bottom, which is meaningless since the container and the
child have the same height already

What happens is when RL sees "align child to bottom," it tries to do
exactly that and grows to take as much space as available, and then
aligns your child to the bottom.

Your two layouts are definitely NOT supposed to be equivalent.

On Mon, May 3, 2010 at 5:57 AM, mbaroukh <mike.baroukh@gmail.com> wrote:
> Hi all.
>
> I suppose it's not a bug but a "works as designed" but I found this to
> be really frustrating.
> The use case is simplified just to the point that is a problem for me.
>
> Here is the first layout that works :
> <?xml version="1.0" encoding="utf-8"?>
> <LinearLayout xmlns:android="http://schemas.android.com/apk/res/
> android"
>    android:layout_width="fill_parent"
>    android:layout_height="wrap_content"
>    android:orientation="vertical"
>>
>                <TextView
>                        android:layout_width="wrap_content"
>                        android:layout_height="wrap_content"
>                        android:text="Test"
>                        android:gravity="center_vertical"
>                />
> </LinearLayout>
>
>
> and the layout that doesn't works :
> <?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_width="wrap_content"
>                        android:layout_height="wrap_content"
>                        android:text="Test"
>                        android:gravity="center_vertical"
>                        android:layout_alignParentBottom="true"
>                />
> </RelativeLayout>
>
> In the first case, "Test" is written to the top of the screen.
> In the second case, "Test" is written in the miiddle of the screen.
>
> It seems, for me, that LinearLayout perfoems correctly.
> That's not the case for RelativeLayout.
> From my understanding, the two layout should rendre the samething.
>
> Yes, if we remove "alignParentBottom" to the RelativeLayout case, it
> works, but for what I wan't to do, I really need it.
>
> So, does anybody knows if it is really a bug and maybe there is a
> workaround or it is the expected behavior and eventually ... why ?
>
> Thanks a lot !
>
> Mike
>
> --
> You received this message because you are subscribed to the Google
> Groups "Android Developers" group.
> To post to this group, send email to android-developers@googlegroups.com
> To unsubscribe from this group, send email to
> android-developers+unsubscribe@googlegroups.com
> For more options, visit this group at
> http://groups.google.com/group/android-developers?hl=en
>

--
Romain Guy
Android framework engineer
romainguy@android.com

Note: please don't send private questions to me, as I don't have time
to provide private support.  All such questions should be posted on
public forums, where I and others can see and answer them

--
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to android-developers@googlegroups.com
To unsubscribe from this group, send email to
android-developers+unsubscribe@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en

No comments:

Post a Comment