前言

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. goLand工程结构管理

    goLand工程结构管理  转 https://www.jianshu.com/p/eb7b1fd7179e 开始之前请确保安装好了 go语言环境并配置好了gopath环境变量 1.创建一个新目录并打 ...

  2. HttpServletRequestWrapper使用技巧(自定义session和缓存InputStream)

    一.前言 javax.servlet.http.HttpServletRequestWrapper 是一个开发者可以继承的类,我们可以重写相应的方法来实现session的自定义以及缓存InputStr ...

  3. SpringMVC(二四) 视图解析流程

    目标方法无论返回的是string.ModelAndView.View,最终都被解析成modelAndView 关键的实现代码是在springmvc.xml配置文件中定义解析器. 参考代码如下: < ...

  4. Spring监听,ApplicationListener

    import java.util.HashMap; import java.util.Map; import org.apache.commons.lang3.StringUtils; import ...

  5. VBA调用DOS程序两种方法

    Set wsh = VBA.CreateObject("WScript.Shell") 'wsh.Run strExePath & " g", vbHi ...

  6. LR特征维数特别大实时计算问题

    美团 https://tech.meituan.com/machinelearning-data-feature-process.html 维数灾难 待续...

  7. Ubuntu下常用指令

    James最近因为需要尝试着编译Android源代码,系统环境变成了Ubuntu.和熟悉Windows操作系统环境一样,都有过渡的阶段.下面记录常用的操作指令. 分类目录如下: uname -a 查看 ...

  8. 03爬虫 爬取hfutxc成绩

    #-*- coding:utf-8 -*- # -*- coding: utf-8 -*- #encoding:utf-8 import urllib import urllib2 import co ...

  9. BZOJ4432 : [Cerc2015]Greenhouse Growth

    对于高度相同的一段可以合并,用链表从左往右维护这些连续段,每段维护以下信息: $l,r$:表示区间的左右端点. $t,a$:表示在第$t$天结束时它的高度是$a$. $b$:当阳光在左边时它是否会长高 ...

  10. day2_抓包_python基础

    char抓包, 1,作用,定位问题实在前端还是在后端.2.在overview中查看返回码是否正常,一般是200,在看response中是否正常返回数据,可查看请求时间等 2.在sequence视图中的 ...