I've been struggling to lay out two ListViews in a vertical LinearLayout. I finally saw the answer on here about wrapping each in their own LinearLayout, and adding each one of these LinearLayouts to the original LinearLayout with weights of 1. So that's what I tried... but I just cannot seem to get this to work.
I'm doing this all in code:
public class MyDualList extends LinearLayout
{
private LinearLayout _layout1;
private LinearLayout _layout2;
private ListView _list1;
private ListView _list2;
public MyDualList(Context context, ListView list1, ListView list2)
{
super(context);
_list1 = list1;
_list2 = list2;
_layout1 = new LinearLayout(context);
_layout1.setLayoutParams(new LayoutParams(LayoutParams.FILL_PARENT, 0, 1));
_layout1.addView(_list1, new LayoutParams(LayoutParams.FILL_PARENT, LayoutParams.FILL_PARENT));
_layout2 = new LinearLayout(context);
_layout2.setLayoutParams(new LayoutParams(LayoutParams.FILL_PARENT, 0, 1));
_layout2.addView(_list2, new LayoutParams(LayoutParams.FILL_PARENT, LayoutParams.FILL_PARENT));
addView(_layout1);
addView(_layout2);
}
}
This is my latest attempt, but I swear I've tried every combination/setting for the LayoutParams' height (FILL_PARENT, WRAP_CONTENT, 0) as well as various weights.
The result is never very good; if my second list is very long, it inevitably takes up the vast majority of the original vertical layout (certainly much more than 50%).
I'm not going to give up! Maybe someone can help me out a bit.
Thanks, Ken