【问题标题】:How can I completely hide the groupIndicator of an ExpandableListView?如何完全隐藏 ExpandableListView 的 groupIndicator?
【发布时间】:2011-08-16 17:37:43
【问题描述】:

我想在自定义 ExpandableListView 中完全隐藏 groupIndicator。

here 提供的示例似乎不起作用。

它建议制作一个选择器并使用我复制的 expList.setGroupIndicator(selector):

<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android" android:id="@+id/empty_icon">
    <item android:state_empty="true" android:drawable="@android:color/transparent"/>
    <item android:state_expanded="true" android:drawable="@android:color/transparent" />
    <item android:drawable="@android:color/transparent" />
</selector>

这会产生以下错误
ERROR/AndroidRuntime(10675): Caused by: android.content.res.Resources$NotFoundException: Resource is not a Drawable (color or path): TypedValue{t=0x12/d=0x0 a=2 r=0x7f0b0013}

使用 android:id/empty 代替 color/transparent 的类似建议给出了同样的建议。

我怎样才能完全隐藏组指示器?

编辑:事实证明,该代码确实有效...如果您将其放在可绘制资源文件夹而不是布局中。

【问题讨论】:

    标签: android expandablelistview


    【解决方案1】:

    你可以试试这段代码

    listView = (ExpandableListView) view.findViewById(R.id.listView);

    listView.setGroupIndicator(null);
    
    
    listView.setChildIndicator(null);
    

    【讨论】:

      【解决方案2】:

      我遇到了同样的问题,这解决了我的问题。 在您的 Listview 的适配器中,将以下内容添加到 getGroupView。

      if (groupPosition == 0) {
           convertView = layoutInflater.inflate(R.layout.blank_layout, null);
      
      } else {
          convertView = layoutInflater.inflate(R.layout.group_indicator_cell,null);
      }
      

      这将使列表的第 0 组空白。

      空白布局是一个布局,里面有一些视图,layout_height=0dp。 有用!

      【讨论】:

        【解决方案3】:

        你试过改变ExpandableListView的属性android:groupIndicator="@null"吗?

        【讨论】:

        • 对于任何想要以编程方式执行此操作的人,都可以通过mExpandableListView.setGroupIndicator(null) 完成。
        猜你喜欢
        • 1970-01-01
        • 2011-06-08
        • 2019-07-22
        • 1970-01-01
        • 2014-12-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多