首页 > 解决方案 > 分隔线未显示在 ExpandableListView Android 中的第一个元素之上

问题描述

我正在使用ExpandableListView,一切正常。但是有一件事真的很烦人,它没有显示divider在第一个元素的顶部,如下图所示。任何建议都将受到高度评价

在此处输入图像描述

标签: android

解决方案


分隔线应该放在底部,而不是放在物品的顶部。有解决方法。在您的文件夹中创建分隔线,Drawable如下所示:

<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
    android:shape="line">
    <stroke
        android:width="1dp"
        android:color="@color/backgroundGray" />
</shape>

给它你想要的颜色。

现在在您的 XML 中ExpandableListView执行以下操作:

<LinearLayout
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical">

    <View
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:background="@drawable/divider_gray"/>
    
    <ExpandableListView
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:divider="@drawable/divider_gray"/>
</LinearLayout>

这样,您将在顶部有一个分隔线,ExpandableListView并且在项目之间也ExpandableListView将有相同的分隔线。


推荐阅读