ori*_*rel 97 android listview divider
我有这个代码:
<ListView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/cashItemsList"
android:cacheColorHint="#00000000"
android:divider="@drawable/list_divider"></ListView>
Run Code Online (Sandbox Code Playgroud)
在哪里@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>
Run Code Online (Sandbox Code Playgroud)
但我看不到任何分隔线.
Joe*_*nte 175
伙计们,这就是你应该使用1px而不是1dp或1dip的原因:如果指定1dp或1dip,Android会将其缩小.在一个120dpi的设备上,它变成类似于0.75px的翻译,其转向为0.在某些设备上,转换为2-3像素,并且它通常看起来很丑或很邋
对于分频器,如果你想要一个像素分频器,1px是正确的高度,并且是"一切应该倾斜"规则的例外之一.它在所有屏幕上都是1像素.另外,1px通常在hdpi和屏幕上看起来更好
"它不再是2012"编辑:您可能必须从特定屏幕密度开始切换到dp/dip
Mik*_*nen 53
这是一种解决方法,但对我有用:
创建res/drawable/divider.xml如下:
<?xml version="1.0" encoding="UTF-8"?>
<shape
xmlns:android="http://schemas.android.com/apk/res/android">
<gradient android:startColor="#ffcdcdcd" android:endColor="#ffcdcdcd" android:angle="270.0" />
</shape>
Run Code Online (Sandbox Code Playgroud)
在styles.xml项目的styles.xml中,我添加了以下行:
<item name="android:divider">@drawable/divider</item>
<item name="android:dividerHeight">1px</item>
Run Code Online (Sandbox Code Playgroud)
关键部分是包括这个1px设置.当然,drawable使用渐变(1px),这不是最佳解决方案.我尝试使用中风,但没有让它工作.(你似乎没有使用样式,所以只需为ListView添加android:dividerHeight ="1px"属性.
小智 26
添加android:dividerHeight="1px",它将工作:
<ListView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/cashItemsList"
android:cacheColorHint="#00000000"
android:divider="@drawable/list_divider" android:dividerHeight="1px"></ListView>
Run Code Online (Sandbox Code Playgroud)
Jus*_*ser 15
一些问题源于你缺少android:dividerHeight,你需要的事实,以及你试图在你的drawable中指定一个线宽的事实,你不能用一些分隔线做一些奇怪的原因.基本上为了使您的示例工作,您可以执行以下操作:
将您的drawable创建为矩形或直线,无论是否工作,您都无法尝试在其上设置任何尺寸,因此:
<shape xmlns:android="http://schemas.android.com/apk/res/android" android:shape="line">
<stroke android:color="#8F8F8F" android:dashWidth="1dp" android:dashGap="1dp" />
</shape>
Run Code Online (Sandbox Code Playgroud)
要么:
<shape xmlns:android="http://schemas.android.com/apk/res/android" android:shape="rectangle">
<solid android:color="#8F8F8F"/>
</shape>
Run Code Online (Sandbox Code Playgroud)
然后创建一个自定义样式(只是一个偏好,但我喜欢能够重用的东西)
<style name="dividedListStyle" parent="@android:style/Widget.ListView">
<item name="android:cacheColorHint">@android:color/transparent</item>
<item name="android:divider">@drawable/list_divider</item>
<item name="android:dividerHeight">1dp</item>
</style>
Run Code Online (Sandbox Code Playgroud)
最后使用自定义样式声明列表视图:
<ListView
style="@style/dividedListStyle"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/cashItemsList">
</ListView>
Run Code Online (Sandbox Code Playgroud)
我假设您知道如何使用这些片段,如果不让我知道.基本上你的问题的答案是你不能在drawable中设置分隔符厚度,你必须在那里保留未定义的宽度并使用android:dividerHeight来设置它.
来自doc:
public void setDivider(Drawable divider) on ListView
/**
* Sets the drawable that will be drawn between each item in the list. If the drawable does
* not have an intrinsic height, you should also call {@link #setDividerHeight(int)}
*
* @param divider The drawable to use.
*/
Run Code Online (Sandbox Code Playgroud)
看起来setDividerHeight()必须调用才能让分隔符显示它没有内在高度
小智 5
你@drawable/list_divide应该看起来像这样:
<shape
xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="line">
<stroke
android:height="1dp"
android:color="#8F8F8F"
android:dashWidth="1dp"
android:dashGap="1dp" />
</shape>
Run Code Online (Sandbox Code Playgroud)
在您的版本中,您提供了一个android:width="1dp",只需将其更改为一个android:height="1dp",它应该工作!
| 归档时间: |
|
| 查看次数: |
165290 次 |
| 最近记录: |