当前位置: 首页 > news >正文

ExpandableListView使用(三)-ScrollView嵌套ExpandableListView,列表显示不全

 

前言

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

相关文章:

  • ORACLE中的各种数据类型详细的介绍
  • 一个简单的golang json解析库
  • Java Web笔记 – Servlet中的Filter过滤器的介绍和使用 编写过滤器
  • java.lang.UnsatisfiedLinkError: no rxtxSerial in java.library.path
  • maven中jar、war、pom的区别
  • 尝试使用word发布博客
  • Python之优先级问题(待修改)
  • Algs4-2.2.23-3根据经验给出应该在何时为子数组切换到插入排序
  • 提高Vector容器的删除效率
  • Hadoop生态系统之HDFS
  • 使用迅雷下载百度网盘2G以上文件
  • JavaScript学习(一)
  • hadoop2.2.0 + hbase 0.94 + hive 0.12 配置记录
  • NOIP2018提高组省一冲奖班模测训练(四)
  • 自己封装的BaseDao--更加灵活方便--hashmap
  • LintCode 31. partitionArray 数组划分
  • MyEclipse 8.0 GA 搭建 Struts2 + Spring2 + Hibernate3 (测试)
  • nginx 负载服务器优化
  • supervisor 永不挂掉的进程 安装以及使用
  • Terraform入门 - 1. 安装Terraform
  • vue的全局变量和全局拦截请求器
  • 官方新出的 Kotlin 扩展库 KTX,到底帮你干了什么?
  • 欢迎参加第二届中国游戏开发者大会
  • 类orAPI - 收藏集 - 掘金
  • 免费小说阅读小程序
  • 让你的分享飞起来——极光推出社会化分享组件
  • 线性表及其算法(java实现)
  • 详解移动APP与web APP的区别
  • 小程序开发之路(一)
  • 【云吞铺子】性能抖动剖析(二)
  • elasticsearch-head插件安装
  • scrapy中间件源码分析及常用中间件大全
  • 分布式关系型数据库服务 DRDS 支持显示的 Prepare 及逻辑库锁功能等多项能力 ...
  • 国内开源镜像站点
  • ​一帧图像的Android之旅 :应用的首个绘制请求
  • #gStore-weekly | gStore最新版本1.0之三角形计数函数的使用
  • #Linux(Source Insight安装及工程建立)
  • %@ page import=%的用法
  • (C语言)球球大作战
  • (附源码)ssm经济信息门户网站 毕业设计 141634
  • (官网安装) 基于CentOS 7安装MangoDB和MangoDB Shell
  • (六)激光线扫描-三维重建
  • (论文阅读32/100)Flowing convnets for human pose estimation in videos
  • (原)Matlab的svmtrain和svmclassify
  • (转) ns2/nam与nam实现相关的文件
  • (转)程序员疫苗:代码注入
  • .mkp勒索病毒解密方法|勒索病毒解决|勒索病毒恢复|数据库修复
  • .MSSQLSERVER 导入导出 命令集--堪称经典,值得借鉴!
  • .NET 4 并行(多核)“.NET研究”编程系列之二 从Task开始
  • .NET 5种线程安全集合
  • .net core IResultFilter 的 OnResultExecuted和OnResultExecuting的区别
  • .NET Core 通过 Ef Core 操作 Mysql
  • .Net Core 中间件验签
  • .Net Remoting(分离服务程序实现) - Part.3
  • .NET 程序如何获取图片的宽高(框架自带多种方法的不同性能)