实现两个ListView在Scrollview中同时滑动
private void setListHeight(ListView listView) {
ListAdapter list = listView.getAdapter();
if (list == null) {
return;
}
int height = 0;
for (int i = 0; i < list.getCount(); i++) {
View listItem = list.getView(i, null, listView);
listItem.measure(0, 0); // 计算子项View 的宽高
height += listItem.getMeasuredHeight(); // 统计所有子项的总高度
}
ViewGroup.LayoutParams params = listView.getLayoutParams();
params.height = height
+ (listView.getDividerHeight() * (list.getCount() - 1));
// listView.getDividerHeight()获取子项间分隔符占用的高度
// params.height最后得到整个ListView完整显示需要的高度
listView.setLayoutParams(params);
private void setListHeight(ListView listView) {
ListAdapter list = listView.getAdapter();
if (list == null) {
return;
}
int height = 0;
for (int i = 0; i < list.getCount(); i++) {
View listItem = list.getView(i, null, listView);
listItem.measure(0, 0); // 计算子项View 的宽高
height += listItem.getMeasuredHeight(); // 统计所有子项的总高度
}
ViewGroup.LayoutParams params = listView.getLayoutParams();
params.height = height
+ (listView.getDividerHeight() * (list.getCount() - 1));
// listView.getDividerHeight()获取子项间分隔符占用的高度
// params.height最后得到整个ListView完整显示需要的高度
listView.setLayoutParams(params);
}
实现让两个GridView同时滑动的方法在ScrollView中:
public class MyGridView extends GridView {
public MyGridView(Context context) {
super(context);
}
public MyGridView(Context context, AttributeSet attrs) {
super(context, attrs);
}
public MyGridView(Context context, AttributeSet attrs, int defStyle) {
super(context, attrs,