Android:ExpandableListview 中的分隔线高度不同

标签 android height parent-child expandablelistview

我的应用程序中有一个自定义可扩展项,我希望标题 (5dp) 和子项 (1dp) 的分隔高度不同。我怎么办?这是我的代码:

bus_info.xml

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >

<ExpandableListView
    android:id="@+id/expandableBus"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:layout_marginTop="3dp"
    android:divider="@drawable/expandable_borde_padre"
    android:childDivider="@drawable/expandable_borde_hijo"
    android:groupIndicator="@drawable/expandable"
    android:scrollbars="none"/>

</LinearLayout>

可扩展.xml

<selector xmlns:android="http://schemas.android.com/apk/res/android">
      <item android:drawable="@drawable/expandable_abajo" android:state_empty="true"/>
      <item android:drawable="@drawable/expandable_arriba" android:state_expanded="true"/>
      <item android:drawable="@drawable/expandable_abajo" />
</selector>

expandable_borde_padre.xml

<shape xmlns:android="http://schemas.android.com/apk/res/android" 
      android:shape="rectangle">
     <solid android:color="@color/negro"/>
     <size android:height="1dp"/>
</shape>

expandable_borde_hijo.xml

<shape xmlns:android="http://schemas.android.com/apk/res/android" 
    android:shape="rectangle">
    <solid android:color="@color/blanco"/>
    <size android:height="1dp"/>
</shape>

如果我将 expandable_borde_padre 中的 更改为 5dp,子项中也会更改

expandable_hijo.java

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="55dip"
android:orientation="vertical" 
android:background="#000000">

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

</LinearLayout>

expandable_padre.java

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/fondoExpandablePadre"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
android:padding="8dp" 
android:background="#000000">


<TextView
    android:id="@+id/lblListHeader"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:paddingLeft="1dp"
    android:textSize="15sp"
    android:textColor="#000000" />

</LinearLayout>

最佳答案

将 divider 和 childdivider 都设置为 null。 使用带有自定义分隔线的自定义标题和 subview 。

例如:

对于标题:

< TextView>

< /TextView>

< View android:height:"5dp">
< /View>

对于 child :

< TextView>

< /TextView>

< View android:height:"1dp">
< /View>

关于Android:ExpandableListview 中的分隔线高度不同,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21878587/

相关文章:

android - Kotlin Android 扩展和保留 fragment

android - 通知高度不正确 "match_parent"

css - Twitter Bootstrap Accordion 固定大小百分比

css - 防止子元素使用父类

Django-管理员 : Editing child model without inlineForm

java - Android:将对象上传到服务器的进度条

Android - SSL/TLS 和 ECC(椭圆曲线加密)

android - 我可以使用字符串资源在 Jetpack Navigation XML 文件中生成深层链接吗?

objective-c - iPhone 4.0 与模拟器中显示的标签高度差异

c - 无法从子进程内部将数据写入文件