【问题标题】:Missing divider lines in android list viewandroid列表视图中缺少分隔线
【发布时间】:2014-07-23 03:06:34
【问题描述】:

我正在构建一个在主屏幕中包含多个列表项的应用程序。 主屏配置如下:

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical" android:layout_width="fill_parent"
android:layout_height="fill_parent" android:weightSum="1">
<ImageView android:id="@+id/home_header" android:src="@drawable/home_header"
    android:layout_width="fill_parent" android:layout_height="wrap_content"></ImageView>

<LinearLayout android:layout_width="match_parent"
    android:layout_height="wrap_content" android:orientation="vertical"
    android:layout_gravity="top" android:id="@+id/HomeOptions">
    <!-- android:textFilterEnabled="true" -->
    <ListView android:id="@+id/HomeOptionsList"
        android:layout_width="fill_parent" android:layout_height="wrap_content">
    </ListView>
</LinearLayout>

列表项的配置如下:

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

<TableRow android:id="@+id/listItem" android:layout_width="wrap_content"
    android:layout_height="wrap_content">
    <ImageView android:id="@+id/icon" src="@drawable/icon"
        android:layout_width="wrap_content" android:layout_height="match_parent" />
    <TextView android:id="@+id/chat_type" android:textStyle="normal"
        android:paddingTop="12dp" android:paddingLeft="5dp"
        android:layout_width="wrap_content" android:layout_height="match_parent" android:textSize="20px"/>
    <ImageView android:id="@+id/home_msg_notification_icon" src="@drawable/message_recieved" android:paddingLeft="50dp"
        android:layout_width="match_parent" android:layout_height="match_parent"
        android:layout_gravity="right" />
    <!-- <ImageView android:id="@+id/error_notification_icon" src="@drawable/warning_icon" android:paddingLeft="50dp"
        android:layout_width="match_parent" android:layout_height="match_parent"
        android:layout_gravity="right" /> -->
</TableRow>

输出屏幕有一个奇怪的问题,它没有显示少数项目的分隔线。当我尝试拖动列表项时,分隔线出现然后消失。我已附上屏幕截图供您查看。

点击here

【问题讨论】:

标签: android android-listview


【解决方案1】:

在低分辨率设备(320x240,如 HTC wildfire)中,列表分隔符并不总是显示。 在滚动过程中,相同的分隔线可以出现和消失。

我来自于分隔线高度的大小近似。

在 ListView 中,默认分隔线高度是可绘制分隔线的大小,我可以在 Android 源代码中看到 1px 高度,在低分辨率设备上显示它,原因不明,为 1px 或 0px。当大小四舍五入为 0px 时,分隔线消失。

为了确保它在所有设备上都能正确显示,我通常以 px 为单位定义 dividerHeight 如:

android:dividerHeight="1px"

【讨论】:

    【解决方案2】:

    mListView.setDividerHeight(1);

    如果您在旧设备上使用 0.5dip,它不会显示

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2018-02-07
      • 1970-01-01
      • 2013-05-02
      • 1970-01-01
      • 2014-08-22
      • 1970-01-01
      相关资源
      最近更新 更多