Problems with LinearLayout

Put your problem here if it does not fit any of the other categories.

Problems with LinearLayout

Postby bAZtARd » Wed Apr 09, 2008 3:35 pm

Hi. i have some stupid problem with LinearLayout. I'm sure it a dumb mistake. but i don't know what i'm doing wrong. i don't want to use xml files. but it should be possible to do the same layout stuff in Java code, shouldn't it?

so. if have this piece of code:
Syntax: [ Download ] [ Hide ]
Using java Syntax Highlighting
  1.     public void onCreate(Bundle icicle) {
  2.  
  3.         super.onCreate(icicle);
  4.  
  5.         LinearLayout ll = new LinearLayout(this);
  6.  
  7.         //ll.setOrientation(LinearLayout.VERTICAL);
  8.  
  9.         TextView tv = new TextView(this);
  10.  
  11.         tv.setText("Foo");
  12.  
  13.         TextView tv2 = new TextView(this);
  14.  
  15.         tv2.setText("Bar");
  16.  
  17.         ll.addView(tv, new LinearLayout.LayoutParams(LinearLayout.LayoutParams.FILL_PARENT,LinearLayout.LayoutParams.FILL_PARENT));
  18.  
  19.         ll.addView(tv2, new LinearLayout.LayoutParams(LinearLayout.LayoutParams.FILL_PARENT,LinearLayout.LayoutParams.FILL_PARENT));
  20.  
  21.  
  22.  
  23.         setContentView(ll);
  24.  
  25. }
Parsed in 0.032 seconds, using GeSHi 1.0.8.4


the emulator only shows the first TextView that gets added (in this case: Foo). The second one is just not there. it does not matter if i use orientation or not and how i set it. what's up with the linear layout? what am i doing wrong??

thanx in advance
bAZtARd
Freshman
Freshman
 
Posts: 8
Joined: Wed Apr 09, 2008 11:03 am

Top

Postby sxjthefirst » Wed Apr 09, 2008 3:42 pm

If you change the layout params to FILL_PARENT and WRAP_CONTENT? Give it a try.
sxjthefirst
Developer
Developer
 
Posts: 36
Joined: Wed Mar 12, 2008 7:24 pm

Postby bAZtARd » Wed Apr 09, 2008 3:48 pm

Yeah!
that worked. thanx a lot!

if orientation=horizontal, layout params must be WRAP, FILL
if orientation=vertival, layout params must be FILL, WRAP

BUT WHY? i don't get it...
bAZtARd
Freshman
Freshman
 
Posts: 8
Joined: Wed Apr 09, 2008 11:03 am

Postby sxjthefirst » Wed Apr 09, 2008 3:55 pm

Me neither :) Glad that it worked.
sxjthefirst
Developer
Developer
 
Posts: 36
Joined: Wed Mar 12, 2008 7:24 pm

Top

Return to Other Coding-Problems

Who is online

Users browsing this forum: No registered users and 14 guests