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. HOWTO push kernel repo into

Talk to your Android representative about that, it's a logistics problem.

But the other question is a valid one, why do you want/need a separate git
tree?  All of your patches should be pushed to mainline, right?  If so, you do
not need a separate tree.

All of your patches have been submitted to the proper kernel subsystem
maintainers for inclusion, right?


greg k-h


2. Is Zoom in And Zoom out is Possible for Image View In android............


Is Zooming is possible to do in android for Image view .
I have a images in full screen view, i need to zoom in and zoom out
for that images present in image view .....
Can any body give me suggestions regarding this........

Thanks in advance.........


3. create drawable from image stored on sd card

4. Great books worth the 35$

5. Error in Android documentation

6. Secure data storage (rooted phones)

7. StackOverflowError on a compound view