[Solved] setLayoutParams() hides View

Put problem concerning Views, Layouts and other XML-Resources (like AndroidManifest) here.

[Solved] setLayoutParams() hides View

Postby konic » Fri Oct 09, 2009 1:40 pm

Hi,
here is piece of code in onCreate() of TabActivity:
Syntax: [ Download ] [ Hide ]
Using java Syntax Highlighting
  1. TabWidget tw = getTabWidget();
  2. // take second tab
  3. RelativeLayout rl = (RelativeLayout)tw.getChildTabViewAt(1);
  4. TextView tv = (TextView)rl.getChildAt(1);
  5. ViewGroup.LayoutParams vp = rl.getLayoutParams();
  6. RelativeLayout.LayoutParams rp = new RelativeLayout.LayoutParams(vp);
  7. // these rules are the same as default ones
  8. rp.addRule(RelativeLayout.ALIGN_PARENT_BOTTOM);
  9. rp.addRule(RelativeLayout.CENTER_HORIZONTAL);
  10. // after setting these params TextView disappears from screen.
  11. // it is still in hierarchy (used hierarchyviewer to check it) 'though
  12. tv.setLayoutParams(rp);
  13.  
Parsed in 0.031 seconds, using GeSHi 1.0.8.4

Could somebody explain what is wrong here?
...
P.S. One more strange thing, - Hierarchy Viewer shows that width of this View is 0
although there is some text (Tab 2) !?
Even if I explicitly set width to, say, 100pix, it still shows as 0 in Viewer :(
Last edited by konic on Fri Oct 09, 2009 4:55 pm, edited 1 time in total.
konic
Developer
Developer
 
Posts: 32
Joined: Mon Aug 24, 2009 3:16 pm

Top

Postby konic » Fri Oct 09, 2009 4:52 pm

OK,
problem is solved, although
I still don't know what was so wrong in the first place !?
I just replaced
Syntax: [ Download ] [ Hide ]
Using java Syntax Highlighting
  1.  
  2. ViewGroup.LayoutParams vp = rl.getLayoutParams();
  3.  
  4. RelativeLayout.LayoutParams rp = new RelativeLayout.LayoutParams(vp);
  5.  
  6.  
Parsed in 0.030 seconds, using GeSHi 1.0.8.4

with
Syntax: [ Download ] [ Hide ]
Using java Syntax Highlighting
  1.  
  2. RelativeLayout.LayoutParams rp = new RelativeLayout.LayoutParams(
  3.  
  4.                                                     LayoutParams.FILL_PARENT,
  5.  
  6.                                                     LayoutParams.FILL_PARENT);
  7.  
  8.  
Parsed in 0.033 seconds, using GeSHi 1.0.8.4
konic
Developer
Developer
 
Posts: 32
Joined: Mon Aug 24, 2009 3:16 pm

Top

Return to View, Layout & Resource Problems

Who is online

Users browsing this forum: No registered users and 3 guests