LinearLayout View Tutorial, weight behavior

by maximus-dev » Fri, 13 Nov 2009 07:22:41 GMT

Sponsored Links
 Hi Everyone...

Very short background... I'm currently a C developer (not C++
unfortunately... so no experience with OOP) who writes homebrew for
the nintendo DS. I'm exploring moving away from that platform and
towards the Android.

That said, I'm doing as suggested at the end of the LinearLayout View
tutorial and modifying the weight values to see how it affects the
size of the columns and rows. The structure seemed very simple, so it
seemed obvious that modifying the first weight (the top half) to 2
should give the top section 2/3rds of the screen and the bottom only
1/3rd. Instead... it appeared to be reversed... the upper area had
become the smaller third (this is in the emulator... I do not have
actual hardware yet).

I tested the same idea on the color columns and the more expected
result occured... the columns with greater weight were now wider and
seemed to take up the correct fractional area of the screen.

Any particular reason for this behavior?

Thanks everyone,


LinearLayout View Tutorial, weight behavior

by Indicator Veritatis » Fri, 13 Nov 2009 09:20:27 GMT


The most likely explanation is that you did not modify the weight you
thought you did. The very first occurrence of the layout_weight
attribute is in the outermost LinearLayout, so it applies to the
entire screen, not to the upper half alone (the color bands). To
change the weight only for the latter, you need to change the SECOND
occurrence of the layout_weight attribute.

Of course, that still doesn't explain the reverse behavior you
described, but at least it is a start.

Now concerning your background: it is impressive that you have made
this much progress in Android w/o an OOP background, but you will make
it much easier on yourself if you take the time out to learn at least
the elements of OOP using Java before putting too much effort into
Android. All the Android documentation and tutorials do assume a
fairly high level of familiarity with these elementary facts about


Sponsored Links

LinearLayout View Tutorial, weight behavior

by Indicator Veritatis » Fri, 13 Nov 2009 09:38:41 GMT

 Or so I thought on first reading. But no, I was misled by the small
frame in the tutorial. Now that I have it running in the emulator
myself, I see the exact same thing you saw.

OTOH, the behavior is closer to what is to be expected (based on the
tutorial) if you change from the default only the weight in the green
band, changing from 1 to 2: then the green band is approximately twice
as big as the red and blue, but the yellow falls somewhere in between!

It looks like the layout manager is not perfect.


LinearLayout View Tutorial, weight behavior

by maximus-dev » Mon, 16 Nov 2009 12:45:05 GMT

 hanks for taking a look at this. Glad to know I'm not just crazy.
It's not a big deal, I'm not likely to use this particular layout, I
don't think.

Very shortly after this I pulled up the tutorials right on Sun's site
and started reading. It was apparent that although some syntax was
similar that the style is dramatically different. It's quite
fascinating... I'm trying very hard not to make comparisons to C. The
more I read, the more I can see that making comparisons would be a
huge mistake.

Is this the kind of thing I should be reporting somewhere?

On Nov 12, 5:38pm, Indicator Veritatis <> wrote:


LinearLayout View Tutorial, weight behavior

by maximus-dev » Mon, 16 Nov 2009 12:46:40 GMT

 Trying to reply again... it didn't show up last time.

I actually stopped right after this and started reading the java
tutorial on sun's website. It's very enlightening.

Is this something that should be reported somewhere?


Other Threads

1. Any body has android VEN_18D1?

Just wandering if any one has android phone VEN_18D1

Manufacturer :  Google, Inc.
Product :       Android Sooner
Info :  53531309d1035cc9
USB Version :   2.00
Product ID :    VEN_18D1,DEV_DEED,PRT_00
Class : Vendor Specific
Max. Packet Size :      64 bytes
Max. Power :    256 mA
Open Pipes :    6



2. How to show a dialog on top of another dialog in an activity

Hi guys!

I have an activity that shows a dialog that has some editText fields
the user is supposed to fill in.  I would like to validate if the user
entered information in some fields, and in case he didn't, I would
like to show a dialog with an appropiate message on top of the
aforementioned dialog.  However I haven't been able to do so, because
once I write code on the onClick(DialogInterface dialog, int
whichButton) of the first dialog, this dialog closes and doesn't stay
in the screen.
Am I missing something?

Here's what I have:
protected Dialog onCreateDialog(int id) {
    return new AlertDialog.Builder(RegisterEvent.this)
            .setPositiveButton(R.string.tv_x_ok, new
DialogInterface.OnClickListener() {
                  public void onClick(DialogInterface dialog, int
whichButton) {
                        if (!validInformation()) // Validates if the
user entered or not information
                                //Here's where I would like to show another 
Best regards,


3. UEventObserver

4. Security library error

5. Research on Android Mobile Platform

6. shared Jar files between different project

7. Launch / Re-Launch flow