因为ListView与ScrollView 都自带了可滑动的功能,但当两者同时使用时会出现冲突
解决的办法是,对Listview进行设置高度即可。
ExpandableListView expandView=(ExpandableListView) findViewById(R.id.ShowItem_ExpandView);
expandView.setAdapter(expandAdapter);
setListViewHeight(expandView);
expandView.setOnGroupClickListener(groupClickLis);
设置ListView的适配器
private ExpandableListAdapter expandAdapter=new ExpandableListAdapter()
{
public void unregisterDataSetObserver(DataSetObserver observer) {
// TODO 自动生成的方法存根
}
public void registerDataSetObserver(DataSetObserver observer) {
// TODO 自动生成的方法存根
}
public void onGroupExpanded(int groupPosition) {
// TODO 自动生成的方法存根
}
public void onGroupCollapsed(int groupPosition) {
// TODO 自动生成的方法存根
}
public boolean isEmpty() {
// TODO 自动生成的方法存根
return false;
}
public boolean isChildSelectable(int groupPosition, int childPosition) {
// TODO 自动生成的方法存根
return false;
}
public boolean hasStableIds() {
// TODO 自动生成的方法存根
return false;
}
public long getGroupId(int groupPosition) {
// TODO 自动生成的方法存根
return 0;
}
public Object getGroup(int groupPosition) {
// TODO 自动生成的方法存根
return null;
}
public long getCombinedGroupId(long groupId) {
// TODO 自动生成的方法存根
return 0;
}
public long getCombinedChildId(long groupId, long childId) {
// TODO 自动生成的方法存根
return 0;
}
public long getChildId(int groupPosition, int childPosition) {
// TODO 自动生成的方法存根
return 0;
}
public Object getChild(int groupPosition, int childPosition) {
// TODO 自动生成的方法存根
return null;
}
public boolean areAllItemsEnabled() {
// TODO 自动生成的方法存根
return false;
}
public int getGroupCount()
{
return 3;
}
public View getGroupView(int groupPosition, boolean isExpanded,
View convertView, ViewGroup parent)
{
return convertView;
}
public int getChildrenCount(int groupPosition)
{
int len=0;
switch(groupPosition)
{
}
return len;
}
public View getChildView(int groupPosition, int childPosition,
boolean isLastChild, View convertView, ViewGroup parent)
{
convertView=webView;
}
return convertView;
}
};
/**
* ExpandableListView 监听
*/
OnGroupClickListener groupClickLis=new OnGroupClickListener()
{
public boolean onGroupClick(ExpandableListView parent, View v,
int groupPosition, long id)
{
setListViewHeight(parent, groupPosition);
return false;
}
};
/**
* 给每一个ListView设置高度
* @param listView
*/
private void setListViewHeight(ListView listView)
{
ListAdapter listAdapter = listView.getAdapter();
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)+50);
listView.setLayoutParams(params);
listView.requestLayout();
}
/**
* 给ExpandableListView 设置高度()
*/
private void setListViewHeight(ExpandableListView listView,int group)
{
ExpandableListAdapter listAdapter = listView.getExpandableListAdapter();
int totalHeight = 0;
int desiredWidth = MeasureSpec.makeMeasureSpec(listView.getWidth(),
MeasureSpec.AT_MOST);
for (int i = 0; i < listAdapter.getGroupCount(); i++)
{
View groupItem = listAdapter.getGroupView(i, false, null, listView);
groupItem.measure(desiredWidth, MeasureSpec.UNSPECIFIED);
totalHeight += groupItem.getMeasuredHeight();
if (((listView.isGroupExpanded(i)) && (i != group))
|| ((!listView.isGroupExpanded(i)) && (i == group)))
{
for (int j = 0; j < listAdapter.getChildrenCount(i); j++)
{
View listItem = listAdapter.getChildView(i, j, false, null,
listView);
listItem.measure(desiredWidth, MeasureSpec.UNSPECIFIED);
totalHeight += listItem.getMeasuredHeight();
}
}
}
ViewGroup.LayoutParams params = listView.getLayoutParams();
int height = totalHeight
+ (listView.getDividerHeight() * (listAdapter.getGroupCount() - 1)+50);
if (height < 10)
height = 200;
params.height = height;
listView.setLayoutParams(params);
listView.requestLayout();
}
}