java - 可扩展 ListView - subview 和组 View 之间的空间

标签 java android xml widget expandablelistview

我正在开发一个简单的待办事项列表应用程序。我使用 ExpandableListView 来显示任务。由于某种原因,我在组 View 和 subview 之间不断出现奇怪的空间。我尝试在 xml 中将分隔线高度设置为 0dp 但它不会改变任何内容。

screenshot of the space

我的 ExpandableListView 的 xml 代码:

<ExpandableListView android:id="@+id/myList"
          android:layout_width="wrap_content" 
          android:layout_height="wrap_content"
          android:layout_below="@+id/addTask"/>

编辑:

subview xml:

 <?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
                android:layout_width="match_parent"
                android:layout_height="130dp"
                android:background="#ff0000">



 <TextView android:layout_width="wrap_content" 
              android:layout_height="wrap_content"
              android:id="@+id/displayDetails"
              android:text="@string/detailsChild"
              android:textColor="#ffffff"/>

父 View xml:

    <?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
              android:layout_width="match_parent"
              android:background="#424242"
              android:layout_height="130dp"
                android:id="@+id/layoutCustom">

<View android:layout_width="fill_parent" android:layout_height="30dp"
      android:background="#FFFFFF"
      android:id="@+id/SpaceView"
      />


 <TextView
                android:layout_below="@id/SpaceView"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:textColor="#FFFFFF"
                android:textSize="16sp"
                android:text="@string/nameofcourse"
                android:id="@+id/course" android:layout_margin="10dp"/>


  <TextView
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="@string/date"
            android:id="@+id/date"
            android:textColor="#FFFFFF"
            android:textSize="16sp"
            android:layout_below="@+id/course"
            android:layout_marginLeft="10dp"/>


<TextView
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_below="@+id/date"
            android:textColor="#FFFFFF"
            android:textSize="16sp"
            android:text="@string/typeoftask"
            android:layout_marginLeft="10dp"
            android:id="@+id/type" android:layout_marginTop="10dp"/>

<Button
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="@string/delete"
            android:textSize="26sp"
            android:textColor="#FE2E2E"
            android:id="@+id/delete"
            android:minWidth="20dp"
            android:minHeight="0dp"
            android:focusable="false"
            android:layout_below="@+id/SpaceView"     android:layout_alignParentRight="true"
            android:layout_alignParentEnd="true"/>

<ImageButton android:layout_width="40dp" android:layout_height="50dp"
             android:id="@+id/mainEdit"
             android:src="@drawable/edit2"
             android:focusable="false"
             android:layout_below="@+id/date"
             android:layout_alignParentRight="true"/>



</RelativeLayout>

谢谢大家,祝你本周愉快!

最佳答案

我不明白到底是什么原因,当我尝试您的layout文件时,即使dividerHeight设置为0dp,它也确实显示了divider,但将一些自定义颜色设置为android:divider并将dividerHeight设置为0dp确实删除了白色空间。我把xml贴在这里,大家可以自己检查一下是否有帮助,

<ExpandableListView android:id="@+id/myList"
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content"
      android:divider="#000" <!-- Use any color or drawable -->
      android:dividerHeight="0dp"
      android:layout_below="@+id/addTask"/>

关于java - 可扩展 ListView - subview 和组 View 之间的空间,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37261192/

相关文章:

c++ - 如何在 cmarkup 生成的 xml 标签中添加更多细节?

c# - 当同一根标签为 'System.SerializableAttribute' 时,重复 "paste xml as classes"属性

java - 在一次调用中将 ArrayList.toString() 转换回 ArrayList

java - 避免复杂 if else 分支的最佳方法 - Java

java - 如何在没有正则表达式的情况下拆分字符串

android - getMenuInflater().inflate(R.menu.main, menu);main无法解析或者不是字段,

Android Facebook SDK 4.0.0 分享回调不正常

Android 应用程序不会在低于 targetSDKVersion 的版本上启动

c# - 处理具有某些相同属性的层次结构中的不同类的最有效方法是什么

java - OpenAPI 生成器在字段级别添加注释