我在滚动视图中有一个列表视图。
为了使其正常工作,我从这里http://www.londatiga.net/it/programming/android/make-android-listview-gridview-expandable-inside-scrollview/
创建了一个自定义列表视图但是当listview中有单个项目时,这也无效。在单个iteam的情况下我无法滚动。
更新: ExpandableHeightListView.java
import android.content.Context;
import android.util.AttributeSet;
import android.view.ViewGroup;
import android.widget.ListView;
/**
* Created by hariram on 10/28/15.
*/
public class ExpandableHeightListView extends ListView {
boolean expanded = false;
public ExpandableHeightListView(Context context) {
super(context);
}
public ExpandableHeightListView(Context context, AttributeSet attrs) {
super(context, attrs);
}
public ExpandableHeightListView(Context context, AttributeSet attrs,
int defStyle) {
super(context, attrs, defStyle);
}
public boolean isExpanded() {
return expanded;
}
@Override
public void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
// HACK! TAKE THAT ANDROID!
if (isExpanded()) {
int expandSpec = MeasureSpec.makeMeasureSpec(
Integer.MAX_VALUE >> 2, MeasureSpec.AT_MOST);
super.onMeasure(widthMeasureSpec, expandSpec);
ViewGroup.LayoutParams params = getLayoutParams();
params.height = getMeasuredHeight();
} else {
super.onMeasure(widthMeasureSpec, heightMeasureSpec);
}
}
public void setExpanded(boolean expanded) {
this.expanded = expanded;
}
}
现在我正在使用此ExpandableHeightListView而不是像
这样的列表视图ExpandableHeightListView listView = (ExpandableHeightListView) getView().findViewById(R.id.expandablelistview);
listView.setExpanded(true);
CustomAdapter customAdapter = new CustomAdapter( getActivity(), resultList);
listView.setAdapter(customAdapter);
如果列表中有多个项目,它可以正常工作,但在单个项目的情况下它不起作用。如果单个列表,我无法滚动。