tags:

views:

34

answers:

1

I need to programmatically adjust the sizes of views in my UI. Say I want to adjust the height of a child view to be the height of the parent view minus 60, I would do this:

child.getLayoutParams().height = parent.getMeasuredHeight() - 60;
child.requestLayout();

(obviously, this is simpler than what I really need to do)

This works great when it is done in response to, say, clicking a button or the like....the child view will adjust its size as requested, and all is well.

Now I need to also have the sizing done when the activity starts, and when the orientation changes. Preferably without seeing anything jump around. I tried adding it to the activity's onStart(), but that doesn't work, as the parent's height measures as zero. I also tried using getHeight() rather than getMeasuredHeight(), and got the same incorrect behavior.

Where do I put this code, or what do I need to do, to programmatically size the views?

A: 

I encountered the same problem. The solution I found on the web is using the child.post() to delay the treatment in the activity onCreate. It works for what I'm doing, but I would love to hear a better solution...

child.post(new Runnable()
    {
      public void run()
      {
        //resize stuff
      }
    }
);
GôTô
Cool I can do that if necessary...
rob