我想要一个包含ViewPager
和RecyclerView
的布局。但在NestedScrollview
内,ViewPager
不会与RecyclerView
滚动。
答案 0 :(得分:1)
根据列表中的项目数量,您必须为RecyclerView
指定固定高度。使用以下函数计算ListView
高度。
public static void setListViewHeightBasedOnChildren(ListView listView) {
ListAdapter listAdapter = listView.getAdapter();
if (listAdapter == null) {
// pre-condition
return;
}
int totalHeight = 0;
for (int i = 0; i < listAdapter.getCount(); i++) {
View listItem = listAdapter.getView(i, null, listView);
listItem.measure(0, 0);
totalHeight += listItem.getMeasuredHeight();
}
ViewGroup.LayoutParams params = listView.getLayoutParams();
params.height = totalHeight + (listView.getDividerHeight() * (listAdapter.getCount() - 1));
listView.setLayoutParams(params);
listView.requestLayout();
}
and
setListViewHeightBasedOnChildren(recyclerView);