Android ListView 默认分隔符样式/属性
我有一个 LinearLayout 视图,我试图向其添加分隔线,以便它看起来与默认的 ListView 控件完全相同。我正在尝试在默认的 Android (Nexus S 2.3.3) 联系人应用程序中复制编辑联系人,我相信 LinearLayout 的性能最佳。
我正在使用代码来复制分隔线,如下所示:
<View
android:id="@+id/Separator"
android:layout_width="fill_parent"
android:layout_height="?android:attr/dividerHeight"
android:background="?android:attr/divider"/>
如何访问默认分隔线颜色或可绘制以及分隔线高度?我希望它与我设置的 ListViews 相匹配,因此我认为使用 Android 系统属性是最好的。上面的代码崩溃了,如下所示,所以我假设我无法访问这些属性或者错误地处理了这个问题。
03-13 22:59:38.851: ERROR/AndroidRuntime(3575): Caused by: java.lang.RuntimeException: Binary XML file line #26: You must supply a layout_height attribute.
I have a LinearLayout view that I am trying to add a divider to so that it looks exactly the same as the default ListView control. I am trying to replicate the edit contact within the default Android (Nexus S 2.3.3) Contacts app and I believe a LinearLayout would be best for performance.
I am using the code to replicate the divider as shown below:
<View
android:id="@+id/Separator"
android:layout_width="fill_parent"
android:layout_height="?android:attr/dividerHeight"
android:background="?android:attr/divider"/>
How can I access the default divider color or drawable and also the divider height? I would like this to match the ListViews I have setup, so using the Android system attributes would be best I think. The above code crashes as shown below so I assume I can't access those attributes or am going about this incorrectly.
03-13 22:59:38.851: ERROR/AndroidRuntime(3575): Caused by: java.lang.RuntimeException: Binary XML file line #26: You must supply a layout_height attribute.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
这是在 Android 源代码
This is how it's done in Android source code
魔术师知识的来源必须是 https://developer.android.com/reference /android/R.attr.html
因此,我所要做的就是在该网站搜索栏中输入“可绘制列表分隔符”或只是“分隔符”
The source of Magician Knowledge must be https://developer.android.com/reference/android/R.attr.html
So all I have to do type in that site search bar - "drawable for the list divider" or just "divider"