ExpandableListView使用(三)-ScrollView嵌套ExpandableListView,列表显示不全
2017-06-14 14:22
393 查看
前言
ScrollView嵌套ExpandableListView会出现ExpandableListView列表显示不全,目前比较好的方法是复写ExpandableListView,重写里面的onMeasure()方法,由于复写的东西并也不多,所以这种方式比较理想示例
SuperExpandableListView.javaimport android.content.Context; import android.util.AttributeSet; import android.widget.ExpandableListView; /** * 解决ScrollView嵌套ExpandableListView时,ExpandableListView显示不全的问题 * Created by 万紫辉 on 2017/6/13 * Email:wzhghgg@gmail.com */ public class SuperExpandableListView extends ExpandableListView { public SuperExpandableListView(Context context) { super(context); } public SuperExpandableListView(Context context, AttributeSet attrs) { super(context, attrs); } public SuperExpandableListView(Context context, AttributeSet attrs, int defStyleAttr) { super(context, attrs, defStyleAttr); } protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) { // TODO Auto-generated method stub int expandSpec = MeasureSpec.makeMeasureSpec(Integer.MAX_VALUE >> 2, MeasureSpec.AT_MOST); super.onMeasure(widthMeasureSpec, expandSpec); } }
使用还是跟原来的ExpandableListView的使用方式是一样的
activity_group_list.xml
<?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:orientation="vertical" android:layout_width="match_parent" android:layout_height="match_parent"> <ScrollView android:layout_width="match_parent" android:layout_height="match_parent" android:orientation="vertical" android:background="@color/gray_light" > <LinearLayout android:layout_width="match_parent" android:layout_height="match_parent" android:orientation="vertical"> <SuperExpandableListView android:id="@+id/elv_teacher_grade" android:layout_width="match_parent" android:layout_height="wrap_content" /> </LinearLayout> </ScrollView> </LinearLayout>
注意
有种方式是设置SrcollView的android:fillViewport=”true” ,这样虽然ExpandableListView可以显示完全,但是ExpandableListView不能滑动,所以这种不能完全解决问题;所以最好的方式是复写ExpandableListView。<ScrollView android:layout_width="match_parent" android:layout_height="match_parent" android:orientation="vertical" android:background="@color/gray_light" android:fillViewport="true"> <LinearLayout android:layout_width="match_parent" android:layout_height="match_parent" android:orientation="vertical"> <ExpandableListView android:id="@+id/elv_teacher_grade" android:layout_width="match_parent" android:layout_height="wrap_content" /> </LinearLayout> </ScrollView>
后续
也有另外一直方法,就是计算ExpandableListView每个列表项的高度,从而确定列表的高度;但是这种方式比较复杂,可以参考,后面会贴出改方法有效参考
ScrollView嵌套ExpandableListView显示不正常的问题相关文章推荐
- ScrollView中嵌套ListView或ExpandableListView时显示不全的问题
- ScrollView嵌套使用ListView时遇到,Item显示不全问题
- [原] 解决在ScrollView中嵌套ListView或ExpandableListView时显示不全的问题
- Android学习 之 问题&解答 ScrollView中嵌套ListView时显示不全的简便解决方案
- ScrollView中嵌套ListView时显示不全的简便解决方案
- 解决ScrollView下嵌套ListView、GridView显示不全的问题(冲突)
- 详解嵌套ListView、ScrollView布局显示不全的问题
- 解决ScrollView下嵌套ListView、GridView显示不全的问题
- ScrollView 嵌套ListView 滑动冲突,与显示不全
- Android中 ScrollView(ListView)中嵌套ListView时显示不全的简便解决方案
- 解决ScrollView下嵌套ListView、GridView显示不全的问题
- 详解嵌套ListView、ScrollView布局显示不全的问题
- 解决ScrollView下嵌套ListView、GridView显示不全的问题
- ScrollView中嵌套ListView时显示不全的解决方案
- Android ScrollView中嵌套ListView和GridView显示不全解决方案
- 关于在ScrollView中嵌套ListView,ListView显示不全的问题
- android ScrollVIew中嵌套GridView,和ListView显示不全解决方法
- ScrollView中嵌套ListView时显示不全的解决方案
- ScrollView 嵌套ListView 幻灯冲突,和显示不全
- 解决ScrollView下嵌套ListView、GridView显示不全的问题