【问题标题】:Android: What's the default value of android:dividerHeight for a listviewAndroid:列表视图的 android:dividerHeight 的默认值是什么
【发布时间】:2013-03-21 18:00:10
【问题描述】:
简单问题:对于普通的列表视图,android:dividerHeight 的默认值是多少?我敢打赌你可能会在某个地方找到它,但我不知道在哪里。
提前致谢!
【问题讨论】:
标签:
java
android
android-layout
android-listview
divider
【解决方案1】:
其他两个答案都只是部分正确。
ListView_dividerHeight 是可设置的,但 Android 本身并没有设置默认值(至少不是普通的 Android)。如果应用程序本身没有设置这样的值,例如:
<item name="android:dividerHeight">5dp</item>
然后@android:drawable/divider_horizontal_dark_opaque 将被使用,它以四种不同的“风格”(ldpi、mdpi、hdpi 和 xhdpi)存在。
所以“真正”的答案是:没有办法说。这取决于:
- 屏幕密度
- 安卓版本
- 制造商定制
- 应用主题
- 可能还有其他因素
要自己找到这些答案,请查看您的 Android SDK 文件夹:platforms\android-17\data\res\values\attrs.xml / styles.xml / theme.xml(android-17 可能因您的安装而异)和阅读有关主题和样式的文档:http://developer.android.com/guide/topics/ui/themes.html
【解决方案2】:
//你可以在你的Android SDK文件夹中看到
分隔符只是一个 9-patch 图像
android-sdk-windows\platforms\android-xx\data\res\values\styles.xml
<style name="Widget.ListView" parent="Widget.AbsListView">
<item name="android:listSelector">@android:drawable/list_selector_background</item>
<item name="android:cacheColorHint">?android:attr/colorBackgroundCacheHint</item>
<item name="android:divider">@android:drawable/divider_horizontal_dark_opaque</item>
</style>
<style name="Widget.ListView.White" parent="Widget.AbsListView">
<item name="android:listSelector">@android:drawable/list_selector_background</item>
<item name="android:cacheColorHint">?android:attr/colorBackgroundCacheHint</item>
<item name="android:divider">@android:drawable/divider_horizontal_bright_opaque</item>
</style>
【解决方案3】:
我敢打赌,这取决于所使用的 android 版本/样式/手机制造商的变化。
快速查看android源码:
TypedArray a = context.obtainStyledAttributes(attrs,
com.android.internal.R.styleable.ListView, defStyle, 0);
// Use the height specified, zero being the default
final int dividerHeight = a.getDimensionPixelSize(
com.android.internal.R.styleable.ListView_dividerHeight, 0);
if (dividerHeight != 0) {
setDividerHeight(dividerHeight);
}