多ExpandableListView不正确凸显 [英] MultiLevel ExpandableListView not highlighting properly

查看:164
本文介绍了多ExpandableListView不正确凸显的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我创建一个自定义的 ExpandableListView 来支持三个层次的使用教程中的这里

I am creating a custom ExpandableListView to support three levels using the tutorial found here.

我有列表和工作的展开/折叠预期。

I have the list working and expanding/collapsing as expected.

我遇到的问题是,当用户presses一个项目,机器人只能识别为可点击区域各个项目的一部分,并且区域是选中时,突出的唯一部分。

The issue I am having is that when a user presses an item, android only recognizes a portion of each item as the clickable area and that area is the only portion that highlights when selected.

如果您运行教程code,或者看看下面的图像,第二级和第三级的背景应该肩负起全宽,就像第一级一样。

If you run the tutorial code, or look at the image below, the Second Level and Third Level backgrounds should take up the full width, just as First Level does.

我已经尝试设置的LayoutParams 我的的TextView 这样的所谓电视:

I have tried setting the LayoutParams on my TextView called tv like this:

tv.setLayoutParams(new ListView.LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT));

我要的背景,并强调要占用各个层面的看法的整个宽度。

I want background and highlighting to take up the full width of the view on every level.

我所有的code的后面的教程,但我可以张贴的某些片段是否会有所帮助。

All of my code follows the tutorial, but I can post specific pieces if it would help.

编辑:添加图片

推荐答案

我找到了解决这个问题,如果有人也需要它。

I found a solution to this issue if anyone also needs it.

CustExpListView 类,你需要重写 onMeasure 方法。

In the CustExpListView class you need to override the onMeasure method.

本教程介绍了用这种方式来做到这一点:

The tutorial shows to do so in this way:

@Override    
protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
    widthMeasureSpec = MeasureSpec.makeMeasureSpec(960, MeasureSpec.AT_MOST);
    heightMeasureSpec = MeasureSpec.makeMeasureSpec(600, MeasureSpec.AT_MOST);
    super.onMeasure(widthMeasureSpec, heightMeasureSpec);
}

不过,这将只使用尽可能必要的宽度以适合文本,因此不突出酒吧。为了解决这个问题修改 onMeasure 方法如下:

@Override
protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec){
    widthMeasureSpec = MeasureSpec.makeMeasureSpec(MeasureSpec.getSize(widthMeasureSpec), MeasureSpec.EXACTLY);
    heightMeasureSpec = MeasureSpec.makeMeasureSpec(Integer.MAX_VALUE, MeasureSpec.AT_MOST);
    super.onMeasure(widthMeasureSpec, heightMeasureSpec);
}

这始终分配宽度到widthMeasureSpec,而如果你已经设置了的LayoutParams MATCH_PARENT 将填补您的看法。高度使用 Integer.MAX_VALUE的,以便第二扩展列表可以使用尽可能多的空间,以便为它的孩子。

This always assigns the width to that of widthMeasureSpec, which if you have set the LayoutParams to MATCH_PARENT will fill your view. The height uses Integer.MAX_VALUE so that the second expandable list may use as much space as necessary for its children.

这篇关于多ExpandableListView不正确凸显的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆