Android ListView 分隔线 [英] Android ListView Divider

查看:37
本文介绍了Android ListView 分隔线的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有这个代码:

<ListView
     android:layout_width="wrap_content"
     android:layout_height="wrap_content"
     android:id="@+id/cashItemsList"
     android:cacheColorHint="#00000000"
     android:divider="@drawable/list_divider"></ListView>

其中 @drawable/list_divider 是:

<shape
 xmlns:android="http://schemas.android.com/apk/res/android"
 android:shape="line">
 <stroke
   android:width="1dp"
   android:color="#8F8F8F"
   android:dashWidth="1dp"
   android:dashGap="1dp" />
</shape>

但我看不到任何分隔线.

but I can't see any divider.

推荐答案

伙计们,这就是为什么您应该使用 1px 而不是 1dp 或 1dip 的原因:如果您指定 1dp 或 1dip,Android 将按比例缩小.在 120dpi 的设备上,它变成了类似 0.75px 转换的东西,它四舍五入为 0.在某些设备上,它转换为 2-3 像素,它通常看起来很难看或马虎

Folks, here's why you should use 1px instead of 1dp or 1dip: if you specify 1dp or 1dip, Android will scale that down. On a 120dpi device, that becomes something like 0.75px translated, which rounds to 0. On some devices, that translates to 2-3 pixels, and it usually looks ugly or sloppy

对于分隔线,如果您想要一个 1 像素的分隔线,则 1px 是正确的高度,并且是一切都应该倾斜"规则的例外之一.它在所有屏幕上都是 1 像素.另外,1px 通常在 hdpi 及以上屏幕上看起来更好

For dividers, 1px is the correct height if you want a 1 pixel divider and is one of the exceptions for the "everything should be dip" rule. It'll be 1 pixel on all screens. Plus, 1px usually looks better on hdpi and above screens

不再是 2012 年了"您可能必须从某个屏幕密度开始切换到 dp/dip

"It's not 2012 anymore" edit: you may have to switch over to dp/dip starting at a certain screen density

这篇关于Android ListView 分隔线的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆