前言

ScrollView嵌套ExpandableListView会出现ExpandableListView列表显示不全,目前比较好的方法是复写ExpandableListView,重写里面的onMeasure()方法,由于复写的东西并也不多,所以这种方式比较理想

示例

SuperExpandableListView.java

import 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每个列表项的高度,从而确定列表的高度;但是这种方式比较复杂,可以参考,后面会贴出改方法

ExpandableListView使用(三)-ScrollView嵌套ExpandableListView,列表显示不全的更多相关文章

  1. ScrollView嵌套ExpandableListView显示不正常的问题

    关于ScrollView嵌套ExpandableListView导致ExpandableListView显示不正常的问题解决方法有非常多,在这里介绍一种小编亲自測试通过的方法. 重写Expandabl ...

  2. ScrollView嵌套Linearlayout显示不全的解决办法

    以为ScrollView只能嵌套一个元素,所以把几个控件都包裹在了一个LinearLayout中了.但是发现底部显示不全,滑动不到最底下. 代码: <ScrollView android:id= ...

  3. scrollview嵌套recyclerview显示不全现象

    只需在recyclerview的外层加入一个父布局就好了 <RelativeLayout android:layout_width="match_parent" androi ...

  4. android listView多层嵌套listView显示不全问题

    最近在做项目,需要用到listVIew多层嵌套listVIew的需求,先发现已下两个处理办法比较好用 第一种: public class ListViewNesting extends ListVie ...

  5. Android--------解决ScrollView中嵌套ExpandableListView显示不全的问题

    ##***Scrollview和ExpandableListView嵌套显示不全*** - 当我们将ExpandableListView嵌套在Scrollview之中时,我们必须要确保我们的不居中Ex ...

  6. ScrollView中嵌套ExpandableListView

    为了让SrollView中嵌套ExpandableListView,我们就得改ListView的高度,所以写一个类继承于ExpandableListview: import android.conte ...

  7. ScrollView嵌套ListView,GridView数据加载不全问题的解决

    我们大家都知道ListView,GridView加载数据项,如果数据项过多时,就会显示滚动条.ScrollView组件里面只能包含一个组件,当ScrollView里面嵌套listView,GridVi ...

  8. 解决ScrollView嵌套RecyclerView出现item显示不全的问题

      问题:ScrollView嵌套RecyclerView时,RecyclerView的item显示不全 出现问题不要慌,耐心解决才是王道,哈哈.首先说下出现这个问题的情景吧,首先声明这个问题在23版 ...

  9. 【转】实现展开列ExpandableListView的三种方式之SimpleExpandableListAdapter实例

    原文网址:http://blog.csdn.net/x605940745/article/details/12099709 实现可扩展展开列ExpandableListView的三种方式 欢迎加入QQ ...

随机推荐

  1. 轻松3步设置sublime text2/sublime text3的预览浏览器

    转https://www.cnblogs.com/swii/p/5888494.html 1,打开sublime 依次选择 tools > build system > new build ...

  2. Web Component

    前言 Web Component不是新东西,几年前的技术,但是受限于浏览器兼容性,一直没有大规模应用在项目里,直到现在(2018年年末),除IE仍不支持之外,其它主流浏览器都支持Web Compone ...

  3. python 数据结构之二分查找的递归和普通实现

    二分查找就是待查找的列表进行分半搜索 如下所示 二分查找普通实现: def erfen(alist, item): start = 0 end = len(alist) - 1 while start ...

  4. Codeforces Round #517 (Div. 2)

    A #include<queue> #include<cstdio> #include<cstring> #include<algorithm> #de ...

  5. Goodbye Wuxu.B.新年的Dog划分(交互 二分 二分图)

    题目链接 官方题解写得很详细,我竟然看懂了. Subtask1: 暴力的话,猜可以\(2^n\)枚举点集\(A,B\),将除了\(A,B\)之间的边全部删掉,然后询问.一定有至少一组\(A,B\)返回 ...

  6. Android的系统属性:build.propSystemProperties

    获取build.prop的键值信息: String sn = SystemProperties.get(SN_INFO); 其中key值为: public static final String SN ...

  7. 【DWM1000】 code 解密9一 ANCHOR response poll message

    根据上面TAG发送的代码,我直接找到如下代码 case RTLS_DEMO_MSG_TAG_POLL: { if(inst->mode == LISTENER)                  ...

  8. Compiling U-Boot

    To configure and build U-Boot for a target board "cd" to, or copy the source tree to somew ...

  9. STM32点亮闪烁LED灯

    详解请看其他博客: http://www.cnblogs.com/whik/p/6672730.html http://www.51hei.com/bbs/dpj-38605-1.html /*本程序 ...

  10. HDU5518 : John's Fences

    求出平面图的对偶图,那么需要选择一些环,使得这些环可以异或出所有环. 对于两个不同的区域,需要用一个代价最小的环把它们区分开,这对应最小割. 那么求出对偶图的最小割树,所有树边之和就是把所有区域都区分 ...