【问题标题】:Divider disappears from last item in listview if footerview added如果添加了页脚视图,分隔线将从列表视图中的最后一项消失
【发布时间】:2011-04-14 10:11:29
【问题描述】:

如果在 ListView 中添加了页脚视图,则分隔符从 ListView 的最后一项消失。

即使我用 ListView 设置了android:footerDividersEnabled="true",我的页脚视图也只是 TextTiew。

【问题讨论】:

    标签: android listview divider


    【解决方案1】:

    isSelectable 设置为true 对我不起作用,可能是因为我在列表加载完成时也调用了removeFooterView

    最终为我解决的问题是将 ListView 上的 android:layout_height 设置为“fill_parent”而不是“wrap_content”。

    【讨论】:

    • 设置 'android:layout_height="fill_parent"' 可以解决问题...非常感谢您的解决方案!!!
    • 非常感谢!只是为了将来的用户注意,使用 match_parent 来实现前向兼容性。不知道 fill_parent 什么时候会被弃用
    【解决方案2】:

    Android 中的ListView 实现不会在禁用的项目之间绘制分隔线,如果您只是调用addFooterView(View v) 方法,那么默认情况下您的页脚将是。

    相反,您需要调用addFooterView(View v, Object data, boolean isSelectable) 方法,并将isSelectable 设置为true。如果不需要,您可以将null 传递给data 对象。

    【讨论】:

    • 是的,添加了一个这样的 footerView: listView.addFooterView(view, null, true) ,它工作得很好......谢谢
    • 这增加了分隔符,但引入了更严重的问题。现在页脚可以点击了!
    【解决方案3】:

    这几乎对我有用。我在最后一个列表项之后有一个分隔符,但不是在页脚之后,因为我的页脚是空白空间。我最终添加了两个页脚,一个可选择零高度,一个不可选择包含填充。

    TextView view = new TextView(this);
    view.setLines(0);
    TextView view1 = new TextView(this);
    view1.setLines(4);
    mListView.addFooterView(view, null, true);
    mListView.addFooterView(view1, null, false);
    mListView.setFooterDividersEnabled(true);
    

    【讨论】:

    • 谢谢,这正是我所需要的!
    【解决方案4】:

    尝试将ListViewlayout_height设置为match_parent

    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:divider="#333333"
    android:dividerHeight="1px"
    

    layout_height 设置为wrap_content 时,它可能会跳过底部分隔符:

    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:divider="#333333"
    android:dividerHeight="1px"
    

    【讨论】:

      【解决方案5】:

      头穿墙的方法,但可靠,是手动添加分隔线作为页脚视图。

      ListView myListView = (ListView) view.findViewById(R.id.my_list_view);
      myListView.addFooterView(getInflater().inflate(R.layout.horizontal_divider, myListView, false), null, false);
      myListView.addFooterView(getInflater().inflate(R.layout.the_original_footer_view, myListView, false), null, false);
      

      布局文件如下所示:

      <View xmlns:android="http://schemas.android.com/apk/res/android"
          android:layout_width="match_parent"
          android:layout_height="1px"
          android:background="?android:attr/dividerVertical" />
      

      即使在最后一个页脚之后,也可以使用这种方法轻松添加分隔线,无论它是可选择的、启用的还是其他任何东西 - 它只是停留在那里。

      注意高度是1px 而不是1dp。尽管违背了所有建议,但至少在我测试的设备上,它提供了与 ListView 相同的分隔高度,而 1dp 没有。

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2021-01-12
        • 2016-07-16
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多