1.ExpandableListView设置默认展
mExpandListview.setAdapter(adapter); //设置ExpandableListView全部展开 for (int i = 0;i < adapter.getGroupCount();i++) { mExpandListview.expandGroup(i); }
2.ExpandableListView设置禁止收缩
//设置不能点击收缩 mExpandListview.setOnGroupClickListener(new ExpandableListView.OnGroupClickListener() { @Override public boolean onGroupClick(ExpandableListView parent, View v, int groupPosition, long id) { return true; } });
3.GridView设置禁止滑动
在ScrollView嵌套GridView时,GridView需要禁止滑动,否则会出现问题,ExpandableListView嵌套时也一样需要
自定义一个类继承于GridView然后重写onMeasure()方法,最后在XML布局中使用自定义的GridView
public class NonScrollGridView extends GridView { public NonScrollGridView(Context context) { super(context); } public NonScrollGridView(Context context, AttributeSet attrs) { super(context, attrs); } public NonScrollGridView(Context context, AttributeSet attrs, int defStyleAttr) { super(context, attrs, defStyleAttr); } //重写此方法可设置GridView禁止滑动 @Override public void onMeasure(int widthMeasureSpec, int heightMeasureSpec) { int expandSpec = MeasureSpec.makeMeasureSpec( Integer.MAX_VALUE >> 2, MeasureSpec.AT_MOST); super.onMeasure(widthMeasureSpec, expandSpec); } }
4.ListView设置禁止滑动(与GridView相同)
在ScrollView嵌套ListView时,ListView需要禁止滑动
自定义一个类继承于ListView 然后重写onMeasure()方法,最后在XML布局中使用自定义的ListView
public class NoScrollListView extends ListView { public NoScrollListView(Context context) { super(context); } public NoScrollListView(Context context, AttributeSet attrs) { super(context, attrs); } public NoScrollListView(Context context, AttributeSet attrs, int defStyleAttr) { super(context, attrs, defStyleAttr); } //重写该方法可设置ListView禁止滑动 @Override public void onMeasure(int widthMeasureSpec, int heightMeasureSpec) { int mExpandSpec = MeasureSpec.makeMeasureSpec(Integer.MAX_VALUE >> 2, MeasureSpec.AT_MOST); super.onMeasure(widthMeasureSpec, mExpandSpec); } }