Android ScrollView嵌套ExpandableListView显示不正常的问题的解决办法

当ScrollView内嵌套ExpandableListView时,可能会出现显示异常。通过重写ExpandableListView的onMeasure方法并设置特定属性,可以解决不显示子View的问题。同时,为使所有子布局可见,需在XML中设置ExpandableListView的divider和dividerHeight属性。
  1.   关于ScrollView嵌套ExpandableListView导致ExpandableListView显示不正常的问题解决方法有很多,在这里介绍一种小编亲自测试通过的方法。
  2. 1:不显示chidview:
  3. 重写ExpandableListView :
  4. public class CustomExpandableListView extends ExpandableListView {  
  5.   
  6.     public CustomExpandableListView(Context context, AttributeSet attrs) {  
  7.         super(context, attrs);  
  8.         // TODO Auto-generated constructor stub  
  9.     }  
  10.   
  11.     @Override  
  12.     protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {  
  13.         // TODO Auto-generated method stub  
  14.         int expandSpec = MeasureSpec.makeMeasureSpec(Integer.MAX_VALUE >> 2,  
  15.   
  16.         MeasureSpec.AT_MOST);  
  17.   
  18.         super.onMeasure(widthMeasureSpec, expandSpec);  
  19.     }  

  1. }  
  2. 在XML中将ExpandableListView替换为重写的ExpandableListView即可。
  3. 此外:要想显示全最后一个子布局:需要在用到ExpandableListView的布局中设置属性
  4. android:divider="@null"
    
    android:dividerHeight="0dp"
    




评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
红包 添加红包
表情包 插入表情
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值