yo uso ese tip, con lo que comenta @elenasys
englobas los dos ListView
en un control ScrollView
y después con esa función setListViewHeightBasedOnChildren
public static void setListViewHeightBasedOnChildren(ListView listView) {
ListAdapter listAdapter = listView.getAdapter();
if (listAdapter == null)
return;
int desiredWidth = View.MeasureSpec.makeMeasureSpec(listView.getWidth(), View.MeasureSpec.UNSPECIFIED);
int totalHeight = 0;
View view = null;
for (int i = 0; i < listAdapter.getCount(); i++) {
view = listAdapter.getView(i, view, listView);
if (i == 0)
view.setLayoutParams(new ViewGroup.LayoutParams(desiredWidth, AbsListView.LayoutParams.WRAP_CONTENT));
view.measure(desiredWidth, View.MeasureSpec.UNSPECIFIED);
totalHeight += view.getMeasuredHeight();
}
ViewGroup.LayoutParams params = listView.getLayoutParams();
params.height = totalHeight + (listView.getDividerHeight() * (listAdapter.getCount() - 1));
listView.setLayoutParams(params);
}
para calcular la altura que debe tener
ListView lv1 = (ListView) findViewById(R.id.listView1);
ListView lv2 = (ListView) findViewById(R.id.listView1);
setListViewHeightBasedOnChildren(lv1);
setListViewHeightBasedOnChildren(lv2);
Método 2
Es crear un control propio extendiendo de un ListView
Crear el control personalizado MyListView.java
public class MyListView extends ListView {
public MyListView (Context context, AttributeSet attrs) {
super(context, attrs);
}
public MyListView (Context context) {
super(context);
}
public MyListView (Context context, AttributeSet attrs, int defStyle) {
super(context, attrs, defStyle);
}
@Override
public void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
int heightSpec;
if (getLayoutParams().height == LayoutParams.WRAP_CONTENT) {
heightSpec = MeasureSpec.makeMeasureSpec(Integer.MAX_VALUE >> 2,MeasureSpec.AT_MOST);
} else {
heightSpec = heightMeasureSpec;
}
super.onMeasure(widthMeasureSpec, heightSpec);
}
}
Y para poder usar el control que se ha creado MyListView
dentro del archivo XML
<tu.package.name.MyListView xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/listview1"
android:layout_width="match_parent"
android:layout_height="wrap_content" />