



Я не уверен в эффективном способе, но работал следующим образом. Во-первых, я создал два динамических ListView и ввел их в одно действие.
Он будет вычислять высоту динамически, а не match_parent.
Вот код:
public void setListViewDynamicHeight(ListView listView) {
ListAdapter adapter = listView.getAdapter();
if (adapter == null) {
return;
}
int height = 0;
int desiredWidth = View.MeasureSpec.makeMeasureSpec(listView.getWidth(), View.MeasureSpec.UNSPECIFIED);
for (int i = 0; i < adapter.getCount(); i++) {
View listItem = adapter.getView(i, null, listView);
listItem.measure(desiredWidth, View.MeasureSpec.UNSPECIFIED);
height += listItem.getMeasuredHeight();
}
ViewGroup.LayoutParams layoutParams = listView.getLayoutParams();
layoutParams.height = height + (listView.getDividerHeight() * (adapter.getCount() - 1));
listView.setLayoutParams(layoutParams);
listView.requestLayout();
}
Вы можете создать его в своем XML-макете следующим образом:
<LinearLayout
android:layout_width = "match_parent"
android:layout_height = "match_parent"
android:orientation = "vertical">
<android.support.v4.widget.NestedScrollView
android:id = "@+id/nested_scroll_view_1"
android:layout_width = "match_parent"
android:layout_height = "match_parent">
<TextView
android:layout_width = "match_parent"
android:layout_height = "wrap_content"
android:text = "Hallo!" />
<!--Other views inside NestedScrollView-->
</android.support.v4.widget.NestedScrollView>
<android.support.v4.widget.NestedScrollView
android:id = "@+id/nested_scroll_view_2"
android:layout_width = "match_parent"
android:layout_height = "match_parent">
<TextView
android:layout_width = "match_parent"
android:layout_height = "wrap_content"
android:text = "Hallo!" />
<!--Other views inside NestedScrollView-->
</android.support.v4.widget.NestedScrollView>
</LinearLayout>
Можете поделиться тем, что пробовали?