Android 列表视图中缺少分隔线
我正在构建一个主屏幕中包含多个列表项的应用程序。 主屏配置如下:
<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>
输出屏幕有一个奇怪的问题,它不显示少数项目的分隔线。当我尝试拖动列表项时,分隔线出现然后消失。我附上了屏幕截图供您查看。
点击此处
I am building an application with multiple list items in the home screen.
Home screen configuration is as follows:
<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>
Configuration of list item is as follows:
<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>
The output screen has a strange problem it does not shows divider lines for few items. When i try to drag the list item, the divider lines appear and then go away. I have attached a screen shot for you to look at.
Click here
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
在低分辨率设备(320x240,如 HTC 野火)中,列表分隔线并不总是显示。
相同的分隔线可以在滚动过程中出现和消失。
I 来自分隔器高度的近似尺寸。
在 ListView 中,默认分隔线高度是可绘制分隔线的大小,如我在 Android 源代码中看到的那样,高度为 1px,在低分辨率设备上显示它,原因未知为 1px 或 0px。当大小舍入为 0px 时,分隔线消失。
为了确保它在所有设备上正确显示,我通常以 px 为单位定义dividerHeight,例如:
In low resolutions devices (320x240 like the HTC wildfire), the list divider is not always displayed.
The same divider can appear and disappear during scrolling.
I comes from the size approximation of the height of the divider.
In the ListView the default divider height is the size of the divider drawable, 1px height as I can see in Android source code, on a low resolution device it's displayed, for an unknown reason as 1px or 0px. The divider disappear when the size is rounded to 0px.
To make sure it's displayed correctly on all devices, I usually define the dividerHeight in px such as:
mListView.setDividerHeight(1);
如果您在旧设备上使用 0.5dip,则不会显示
mListView.setDividerHeight(1);
if you use 0.5dip on older devices it does not display