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. How can use android native dialer to manage call events in our own way


       I want to know how can we make use of  native dialer to make
our own calls.What i want to know here is i want to get events
generated when native buttons pressed but those should be handled as
per my program.

We have TelephonyManager to get events generated when call state is
changed.Here we can get events when call state is changed.

  Any help would be appreciated highly.


2. Intent.ACTION_SEND problems with platform\emulator 1.1

I developed an application using Android SDK 1.5_r2, with API level 2
When I use the Intent ACTION_SEND with an emulator target API level 3
(1.5) I have no problems, and I can choose to send the message between
email or SMS. On the contrary with an emulator target API level 2
(1.1) I got the message "No application can perform this action". I
configured and tested in both targets the same email account.
 Any ideas?!


Here is the snippet of code:

Intent sendIntent = new Intent(Intent.ACTION_SEND);
                        sendIntent.putExtra(Intent.EXTRA_TEXT, "my message");
                        try {
                        } catch (android.content.ActivityNotFoundException ex) {

3. GLES applications sometimes crashes "(SIGSEGV), fault addr 00000150" after turning screen off/on

4. How can I know if I can display a character ?

5. Problem in simple Code SQLite

6. How could I get the size of

7. TabHost Remove Tab problem