【问题标题】:After disabling certain items in the listview, the divider disappears禁用列表视图中的某些项目后,分隔线消失
【发布时间】:2019-03-07 07:57:03
【问题描述】:

禁用列表视图中的某些项目后,分隔线消失。 如何让我的分隔线可见?

作为参考,我发现解决方案说覆盖适配器的 areAllItemsEnabled 并返回 true。但它不起作用。

@Override
  public boolean isEnabled(int position) {
    if (position == 1) {
      return false;
    }
    return true;
  }

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

我的 ListView 如下所示。

<ListView
    android:id="@android:id/list"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:layout_gravity="center"
    android:fastScrollEnabled="true"
    android:horizontalSpacing="@dimen/list_item_padding_horizontal"
    android:listSelector="@drawable/default_list_item_selector"
    android:scrollbars="vertical"
    android:stretchMode="columnWidth"
    android:verticalSpacing="@dimen/list_item_padding_vertical" />

请帮帮我。

【问题讨论】:

  • 你可以为你的问题添加截图吗?
  • 这个链接是完全相同的问题,没有解决方案有帮助。 stackoverflow.com/questions/5375138/…
  • 由于防火墙,我无法上传文件。另外,例如禁用第二项时,第二项的分隔符消失。

标签: android listview divider


【解决方案1】:

您可以在 item_row 布局中添加的最佳选项,您可以轻松地根据您的要求进行自定义。 如下所示:

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

 <TextView
      android:layout_width="wrap_content"
      android:layout_centerVertical="true"
      android:gravity="center"
      android:text="Title"
      android:textColor="@color/black"
  />

   <View
      android:layout_width="match_parent"
      android:layout_height="1dp"
      android:background="@color/grey"
   />

</LinearLayout>

视图用作分隔线/分隔线。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-08-26
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多