【问题标题】:Can't remove the last divider in ListView无法删除 ListView 中的最后一个分隔符
【发布时间】:2014-04-15 11:54:59
【问题描述】:

我有一个ListView,它必须填满父布局中的整个可用空间。我想删除最后一个分隔符,这是我的代码:

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

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

    <ListView
        android:id="@+id/listView"
        android:layout_height="0dp"
        android:layout_weight="1"
        android:layout_width="fill_parent"
        android:choiceMode="singleChoice"
        android:listSelector="@drawable/popup_table_row"
        android:footerDividersEnabled="false"
        android:headerDividersEnabled="false" />

    <Button
        android:id="@+id/cancelbutton"
        android:layout_height="wrap_content"
        android:layout_width="fill_parent"
        android:text="@string/cancel"
        style="@style/ButtonTextBold"
        android:background="@drawable/blue_button" />

</LinearLayout>

android:headerDividersEnabled="false" 什么都不做。最后一个分隔线不会被删除。我尝试使用RelativeLayout 实现布局并将listView 的高度设置为fill_parent,但它也没有帮助。

【问题讨论】:

  • 将分隔线颜色设置为透明。
  • 我不想将分隔线的颜色设置为透明,因为我需要元素之间的分隔线。我只是不需要底部分隔线。
  • 尝试将 listView 的高度设置为 fill_parent 并移除该权重。你也在使用listfragment吗?如果是,请尝试 listFragment.getListView().setFooterDividersEnabled(false);
  • 如果我在LinearLayout 中为第一个元素设置fill_parent,我的其他元素将不可见。不,我不使用ListFragment
  • 不要使用列表视图分隔符。在您的列表视图项目中查看并根据 getview 中的位置处理它的可见性。

标签: android listview android-listview


【解决方案1】:

使用列表视图属性 android:divider="@null"

【讨论】:

    【解决方案2】:

    试试这个

    <ListView
        android:id="@+id/listView1"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_alignLeft="@+id/ibtn_regstepone_fbconnect"
        android:layout_below="@+id/btn_regstepone_alreadymember"
        android:layout_marginTop="59dp" 
        android:divider="@null">
    

    【讨论】:

    • 我无法将 android:divider 设置为 null,因为我需要分隔符。我只是不需要最后一个(底部)分隔线。
    • 感谢您的回答。我在上面写道,我尝试使用RelativeLayout 实现布局并将高度设置为fill_parent,但没有帮助。我的布局在DialogFragment 中被夸大了,也许这就是原因,我不知道。并且不知道如何移除这个底部分隔线。
    猜你喜欢
    • 1970-01-01
    • 2012-12-21
    • 2017-03-26
    • 2013-01-17
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2022-01-24
    • 1970-01-01
    相关资源
    最近更新 更多