如何删除 ExpandableListView 中父级和子级之间的特定空间

2023-12-26

Can you help me identify why there is a space between the group and the child? In my case I want spaces between all groups and the child should be right below the group with no space (but of course space to the next group. My problem looks like this: enter image description here

我已将组分隔符设置为此可绘制对象(expandable_list_group_divider):

<?xml version="1.0" encoding="utf-8"?>

<shape xmlns:android="http://schemas.android.com/apk/res/android">
    <size android:height="10dp"/>
</shape>

以及子分隔符(@drawable/expandable_list_child_divider):

<?xml version="1.0" encoding="utf-8"?>

<shape xmlns:android="http://schemas.android.com/apk/res/android">
    <size android:height="0dp"/>
</shape>

我在 xml 中定义了这样的布局(它是一个复合控件):

<com.jws.MyExpandableListView
        android:id="@+id/expList"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_marginTop="5dp"
        android:layout_marginLeft="15dp"
        android:layout_marginRight="15dp"
        android:scrollbars="none"
        android:divider="@drawable/expandable_list_group_divider"
        android:childDivider="@drawable/expandable_list_child_divider"/>

自定义视图类:

public class MyExpandableListView extends ExpandableListView {
    protected ArrayList<Departure> departures;

    public MyExpandableListView(Context context, AttributeSet attrs) {
        super(context, attrs);

        setGroupIndicator(null);
        setChildIndicator(null);
        setHorizontalFadingEdgeEnabled(true);
        setVerticalFadingEdgeEnabled(true);
        setFadingEdgeLength(60);

        departures = new ArrayList<Departure>();
        this.setAdapter(new MyExpandableListAdapter(context, this, departures));
    }
}

最后是可扩展列表适配器

public class DeparturesExpandableListAdapter extends BaseExpandableListAdapter {
    private final int DIVIDER_HEIGHT = 20;
    private LayoutInflater inflater;
    private ArrayList<Departure> departures;
    private Context context;
    private ExpandableListView expListView;

    public DeparturesExpandableListAdapter(Context context, ExpandableListView expListView, ArrayList<Departure> departures)
    {
        this.context = context;
        inflater = (LayoutInflater) context.getSystemService(context.LAYOUT_INFLATER_SERVICE);
        this.departures = departures;
        this.expListView = expListView;
    }


    // This Function used to inflate parent rows view
    @Override
    public View getGroupView(int groupPosition, boolean isExpanded, View convertView, ViewGroup parentView)
    {
        final Departure departure = departures.get(groupPosition);

        if(!isExpanded)
            expListView.setDividerHeight(DIVIDER_HEIGHT);
        else
            expListView.setDividerHeight(-4);

        expListView.setFooterDividersEnabled(false);

        // Inflate grouprow.xml file for parent rows
        convertView = inflater.inflate(R.layout.view_departure_overview, parentView, false);

        //Data handling in the view...

        return convertView;
    }


    // This Function used to inflate child rows view
    @Override
    public View getChildView(int groupPosition, int childPosition, boolean isLastChild,
                             View convertView, ViewGroup parentView)
    {
        final Departure departure = departures.get(groupPosition);

        if(isLastChild)
            expListView.setDividerHeight(DIVIDER_HEIGHT);

        // Inflate childrow.xml file for child rows
        convertView = inflater.inflate(R.layout.view_departure_details, parentView, false);

        //Data handling...

        return convertView;
    }

    @Override
    public Object getChild(int groupPosition, int childPosition)
    {
        return departures.get(groupPosition);
    }

    //Call when child row clicked
    @Override
    public long getChildId(int groupPosition, int childPosition)
    {
        return childPosition;
    }

    @Override
    public int getChildrenCount(int groupPosition)
    {
        return 1;
    }


    @Override
    public Object getGroup(int groupPosition)
    {
        return departures.get(groupPosition);
    }

    @Override
    public int getGroupCount()
    {
        if(departures != null)
            return departures.size();

        return 0;
    }

    //Call when parent row clicked
    @Override
    public long getGroupId(int groupPosition)
    {
        return groupPosition;
    }

    @Override
    public void notifyDataSetChanged()
    {
        // Refresh List rows
        super.notifyDataSetChanged();
    }

    @Override
    public boolean isEmpty()
    {
        return ((departures == null) || departures.isEmpty());
    }

    @Override
    public boolean isChildSelectable(int groupPosition, int childPosition)
    {
        return false;
    }

    @Override
    public boolean hasStableIds()
    {
        return false;
    }

    @Override
    public boolean areAllItemsEnabled()
    {
        return true;
    }
}

Image for comments: enter image description here


这是经过测试并被证明有效的,我什至想在几个月后回到这个问题,因为其他方法都没有给我带来我想要的结果。这些完全按照OP(和我自己)想要的方式显示

这是我的组或类别或其他什么。基本上,第一个线性布局只是视图的包装器,充当类别之间的间隔符,然后是另一个处理我所有格式的线性布局

在 ExpandableListView(未显示)中,我将分隔线高度设置为 0。间距由视图处理

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:orientation="vertical">

    <View
        android:layout_width="fill_parent"
        android:layout_height="6dp"
        android:background="@android:color/transparent"/>

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:orientation="vertical"
    android:padding="8dp"
    android:background="#50601CBA">


    <TextView
        android:id="@+id/lblListHeader"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:gravity="center"
        android:textSize="17dp"
        android:textColor="#FFFFFF" />

</LinearLayout>
</LinearLayout>

然后在孩子身上我有这个。

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="55dip"
    android:orientation="vertical" >

    <TextView
        android:id="@+id/lblListItem"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:textSize="12sp"
        android:paddingTop="5dp"
        android:paddingBottom="5dp"
        android:textColor="#FFFFFF"
        android:background="#50601CBA"
         />

</LinearLayout>
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

如何删除 ExpandableListView 中父级和子级之间的特定空间 的相关文章

随机推荐

  • fastApi 中的 python 全局变量无法正常工作

    我有一个简单的 fastApi 演示应用程序 它实现了一个功能 通过调用名为changeResponse的post api来获取不同的响应json changeResponse api只是改变了一个全局变量 另一个api通过同一个全局变量返
  • 手机上的陀螺仪漂移

    很多帖子都讨论了陀螺仪漂移问题 有些人说陀螺仪读数有漂移 但其他人说积分有漂移 原始陀螺仪读数有漂移 link https stackoverflow com questions 1586658 combine gyroscope and
  • 在 ASCIIFoldingFilter 中使用静态“foldToAscii”方法

    我一直在使用 ASCII 折叠过滤器来处理变音符号 不仅适用于弹性搜索中的文档 还适用于各种其他类型的字符串 public static String normalizeText String text boolean shouldTrim
  • 单个解析服务器中的多个应用程序

    我花了整整一周的时间将 parse com 上托管的应用程序迁移到解析服务器 设法使一切完美运行 唯一的问题是让它在单个硬件上运行多个应用程序 而无需为此分配服务器应用程序它有 它会变得昂贵 我读了这个讨论 https github com
  • android 多数据源的分页库DataSource.Factory

    我有多个数据源 但只有一个DataSourceFactory 因此 所有来源都共享一个工厂 我需要每个数据源一个 DataSourceFactory 在我的应用程序中 我有多个 RecyclerViews 视图 因此有多个自定义数据源 那么
  • PHP 5.4 中删除 safe_mode 后的安全性在哪里

    我心里有一个棘手的问题 safe modePHP 5 4 中已删除 那么此删除的安全性如何 这是否意味着任何应用程序都可以执行任何程序 为此目的使用什么技术来防止此类暴力行为 本文 http ilia ws archives 18 PHPs
  • java.lang.SecurityException AWSCredentialsProvider 签名者信息不匹配

    我正在使用 2 个亚马逊提供的库 redshift jdbc42 1 2 27 1051 and aws java sdk core 1 11 600 两个库都定义了一个类AWSCredentialsProvider包装下com amazo
  • 将文件从服务器下载到 Ionic2 应用程序中

    我需要在我的中实现一个功能Ionic2用户可以将特定视频文件下载到 Ionic2 应用程序中 经检查Ionic Native部分 我发现以下插件可用 File 文件选择器 文件开启器 文件路径 但找不到诸如 cordova 插件 文件传输
  • 如何在Windows 10上更改Node JS进程名称?

    我有一个node js在 Windows 10 上运行的进程 我想更改进程的名称 以便可以获得一些性能详细信息 我尝试改变流程 标题的财产process对象但是 它不会反映在电源外壳中 我只能找到node作为进程名称 有没有其他方法可以更改
  • Exhaustive-deps 规则无法将自定义挂钩的结果识别为 React 参考

    想象一个钩子 export function useMounted const mounted React useRef
  • Spring Boot 多数据库:没有 EntityManagerFactoryBuilder 类型的合格 bean

    我们的 Spring Boot 应用程序中有两个数据库 称为源数据库和目标数据库 这是这些的配置 源配置 package com alex myapp config import javax persistence EntityManage
  • PHP 字符串类型提示 [关闭]

    就目前情况而言 这个问题不太适合我们的问答形式 我们希望答案得到事实 参考资料或专业知识的支持 但这个问题可能会引发辩论 争论 民意调查或扩展讨论 如果您觉得这个问题可以改进并可能重新开放 访问帮助中心 help reopen questi
  • 如何在另一个线程完成时停止一个线程

    我有这个代码 Thread thread1 new Thread this DoSomething1 Thread thread2 new Thread this DoSomething2 thread1 Start thread2 Sta
  • OpenSSL:加密/解密例程的输入和输出缓冲区可以相同吗?

    例如 在 int EVP EncryptUpdate EVP CIPHER CTX ctx unsigned char out int outl unsigned char in int inl can out in 我只是偶然发现这个问题
  • 如何限制临时表的大小?

    我的数据库中有较大的 InnoDB 表 显然 用户能够使用 JOIN 进行 SELECT 从而生成临时的大型 因此位于磁盘上 表 有时 它们太大以至于耗尽了磁盘空间 导致各种奇怪的问题 有没有办法限制临时表的最大大小对于磁盘上的表 这样表就
  • 将参数值作为rails中的查询字符串传递给redirect_to

    这应该很简单 但我似乎找不到简单的答案 如何将当前请求中的参数值传递到redirect to 调用中 我想将一些表单值传递到 GET 重定向的查询字符串中 我想做这样的事情 redirect to thing foo gt params f
  • 查找多个 NumPy 数组的中值

    我有一个创建大约 50 个数组的 for 循环 数组的长度为 240 我试图找出计算数组每个元素的中值的最佳方法 本质上 我想获取循环中创建的每个数组的第一个元素 将它们放入列表中 然后找到中位数 然后对其他 239 个元素执行相同的操作
  • jit 会优化新对象吗

    我创建这个类是为了不可变并且具有流畅的 API public final class Message public final String email public final String escalationEmail public
  • 唤醒 Heroku 应用程序

    因此 我的 heroku NODE js 应用程序一直在运行 今天我通过我的 url 再次尝试它 但由于某种原因 它给了我一条应用程序错误消息 我阅读并登录到我的仪表板 它说该应用程序正在睡眠 我有 Heroku 的免费套餐 我知道该应用程
  • 如何删除 ExpandableListView 中父级和子级之间的特定空间

    Can you help me identify why there is a space between the group and the child In my case I want spaces between all group