一聚教程网:一个值得你收藏的教程网站

最新下载

热门教程

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

时间:2017-03-28 编辑:简简单单 来源:一聚教程网

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

前言:

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

重写ExpandableListView:

实例代码:

 代码如下 复制代码

packagecom.jph.view;

  

importandroid.content.Context;

importandroid.util.AttributeSet;

importandroid.widget.ExpandableListView;

  

/**

 * 重写ExpandableListView以解决ScrollView嵌套ExpandableListView

 *
导致ExpandableListView显示不正常的问题

 * @author jph

 * Date:2014.10.21

 */

publicclassCustomExpandableListViewextendsExpandableListView {

  

  publicCustomExpandableListView(Context context) {

    super(context);

    // TODO Auto-generated constructor stub

  }

  

  publicCustomExpandableListView(Context context, AttributeSet attrs) {

    super(context, attrs);

    // TODO Auto-generated constructor stub

  }

  

  publicCustomExpandableListView(Context context, AttributeSet attrs,

      intdefStyle) {

    super(context, attrs, defStyle);

    // TODO Auto-generated constructor stub

  }

   @Override 

  protectedvoidonMeasure(intwidthMeasureSpec,intheightMeasureSpec) { 

    // TODO Auto-generated method stub 

    intexpandSpec = MeasureSpec.makeMeasureSpec(Integer.MAX_VALUE >>2,  

    MeasureSpec.AT_MOST);  

    super.onMeasure(widthMeasureSpec, expandSpec); 

  } 

}

在XML中将ExpandableListView替换为重写的ExpandableListView即可。

 代码如下 复制代码

      android:layout_width="match_parent"

      android:layout_height="wrap_content"/>

热门栏目