Android: Draw custom border around listview?

為{幸葍}努か 提交于 2020-01-01 14:55:35

问题


I've got a ListActivity with a ListView in it. I need to draw a repeating image around the border ("on top of it (I guess after the listview is renderered))

How can I hook in my own drawing code for this?


回答1:


You can use a FrameLayout to cause the ListView to overlap with a view that fills the entire screen. In this background view you could tile an image, or write your own custom View with your own drawing method.




回答2:


There is no border property in ListView, as far as I know.

Instead you can put ListView into a FrameLayout and set the Background color of the FrameLayout.

Finally, set some padding to FrameLayout in order to create a border effect.




回答3:


Hi There is one way I have used, but that can be done in XML only. android:background="#ffffff"
android:divider="#ffcccccc" android:dividerHeight="1dip"/>

What I am doing is, putting listview in a LinearLayout. Background color of the list is different than that of layout. There is a margin set for layout. Hence the distance between list and layout will appear like a border for the listview. Hope this helps.



来源:https://stackoverflow.com/questions/3182723/android-draw-custom-border-around-listview

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!