[英]How can i design expendablelistview, recylerview(gridview) in single layout in Android
Previously am designed expandablelistview and recyclerview inside ScrollView but i saw in stack overflow they said this is not good idea,never put a scrollable view inside another scrollable view.Then how can i design this. 以前是在ScrollView中设计的expandablelistview和recyclerview,但是我在堆栈溢出中看到他们说这不是个好主意,切勿将可滚动视图放在另一个可滚动视图中。然后我如何设计它。 This is my previous code: 这是我以前的代码:
<ScrollView
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<LinearLayout
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="wrap_content">
<ExpandableListView
android:id="@+id/secPage_explist"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:choiceMode="singleChoice"
android:groupIndicator="@null"
android:nestedScrollingEnabled="true"
/>
<android.support.v7.widget.RecyclerView
android:id="@+id/grid_recycler_template"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:background="@color/oreser_item_seperator"
/>
</LinearLayout>
</ScrollView>
Please tell me any one. 请告诉我任何一个。
Calculate height of Expandablelistview
and RecyclerView
programatically and Remove Scrollview 以编程方式计算Expandablelistview
和RecyclerView
高度并删除Scrollview
here in below is class that caluclate height of expandable listview 下面是计算可扩展列表视图高度的类
public class Calculate_Height {
public static int calculateHeight_expandable(ExpandableListView list) {
int height = 0;
ExpandableListAdapter listAdapter = list.getExpandableListAdapter();
if (listAdapter == null) {
// pre-condition
return 0;
}
for (int i = 0; i < listAdapter.getGroupCount(); i++) {
View groupItem = listAdapter.getGroupView(i, false, null, list);
groupItem.measure(
MeasureSpec.makeMeasureSpec(0, MeasureSpec.UNSPECIFIED),
MeasureSpec.makeMeasureSpec(0, MeasureSpec.UNSPECIFIED));
height += groupItem.getMeasuredHeight();
if (list.isGroupExpanded(i)) {
for (int j = 0; j <listAdapter.getChildrenCount(i); j++) {
View listItem = listAdapter.getChildView(i, j, false, null,
list);
listItem.measure(MeasureSpec.makeMeasureSpec(0,
MeasureSpec.UNSPECIFIED), MeasureSpec
.makeMeasureSpec(0, MeasureSpec.UNSPECIFIED));
height += listItem.getMeasuredHeight();
}
}
}
height += list.getDividerHeight() * (list.getCount() - 1);
Log.i("height", "" + height);
return height;
}
}
set height of expandalbelistview in oncreate activity 在oncreate活动中设置expandalbelistview的高度
expandable_myitem.setOnGroupExpandListener(new ExpandableListView.OnGroupExpandListener() {
@Override
public void onGroupExpand(int groupPosition) {
expandable_myitem.setLayoutParams(new LinearLayout.LayoutParams(
LinearLayout.LayoutParams.WRAP_CONTENT,
Calculate_Height.calculateHeight_expandable(expandable_myitem)));
}
});
expandable_myitem.setOnGroupCollapseListener(new ExpandableListView.OnGroupCollapseListener() {
@Override
public void onGroupCollapse(int groupPosition) {
expandable_myitem.setLayoutParams(new LinearLayout.LayoutParams(
LinearLayout.LayoutParams.WRAP_CONTENT,
Calculate_Height.calculateHeight_expandable(expandable_myitem)));
}
});
删除滚动视图并为线性布局添加权重,根据布局使用权重用于回收视图和列表视图,否则请使用动态高度代码来管理屏幕。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.