saynomoo/mig4android — Issue #5: Height of a contained ViewGroup is not updated after the initial layout
Author: mikaelgrev
Created: 2012-01-13 20:01:25+00:00
State: open

Hello,

There's a problem when a ViewGroup (and possibly View) changes its height after the initial layout. That ViewGroup's measured size (height at least) doesn't seem to ever get updated after the initial layout. In the example below this shows in that even after the one second delayed addition of an idem the height remains zero.

In the code below it works with the LinearLayout. It also works if the ListView has the items from the beginning or the height is set explicitly. All those cases are commented out.

Works here means that the ListView get the correct, and not 0, size, and that it updates according to the content of the contained ListView.

I would try to fix it myself but I don't know enough about the Android layout system yet so I think you'd fix it faster.

Cheers,
Mikael

'''Java
final Handler handler = new Handler();
final ListView view1 = new ListView(this);

// With this line it works
//	view1.setAdapter(new ArrayAdapter(view1.getContext(), android.R.layout.simple_list_item_1, new String[] {"hello, world " + Math.random()}));

new Timer().scheduleAtFixedRate(new TimerTask() {
public void run() {
handler.post(new Runnable()
{
public void run()
{
view1.setAdapter(new ArrayAdapter(view1.getContext(), android.R.layout.simple_list_item_1, new String[] {"hello, world " + Math.random()}));
}
});
}
}, 1000, 1000);

MigLayout layout = new MigLayout(this);
layout.addView(view1);
//	layout.addView(view1, "h 100"); // with this line it works

//	LinearLayout layout = new LinearLayout(this);
//	layout.addView(view1);

setContentView(layout);
'''