- 浏览: 1423710 次
文章分类
最新评论
-
shrimp0526:
大神您写的这个工具还在么?能不能提供一个国内的下载地址?
Java版文件编码转换工具 -
流逝记忆:
感谢分享
Android音乐播放器【安卓进化二十】 -
hgq0011:
java能调用吗?谢谢
利用微软的SAPI进行语音合成 -
penkee:
怎样不弹出 视频压缩 选择压缩程序的窗口求教
C#将图像文件压缩为AVI文件播放 -
流动的阳光:
有用,mark!
Android中使用自定义的字体
listView属性及方法小析
关于listview的小例子,以前也写过一个,http://blog.csdn.net/aomandeshangxiao/article/details/6643831,今天的这篇文章主要是说一下listview里面的方法和属性,内容均来自:http://developer.android.com/reference/android/widget/ListView.html。摘取了一下自己认为重要的方法。
首先,看下xml中的属性,divider:
规定List项目之间用某个图形或颜色来分隔。可以用"@[+] [package:]type:name"或者"?[package:][type:]name"(主题属性)的形式来指向某个已有资源;也可以用"#rgb","#argb","#rrggbb"或者"#aarrggbb"的格式来表示某个颜色。
可参看全局属性资源符号divider。
就是listview的item之间的分割线,可以设置为图片或者设置为一种颜色,在xml文件中,可以设置它的颜色或者图片,在代码中只提供了设置图片的方法:
和设置分割线高度的方法:
第二个属性:entries
引用一个将使用在此ListView里的数组。若数组是固定的,使用此属性将比在程序中写入更为简单。
必须以"@[+][package:]type:name"或者"?[package:][type:]name"的形式来指向某个资源。
跟这个属性相关的方法就是使用setAdapter(),关于这个方法,在这里就不累述了。
第三个属性:footerDividersEnabled
设成flase时,此ListView将不会在页脚视图前画分隔符。此属性缺省值为true。
属性值必须设置为true或false。
可以用"@[package:]type:name
"或者"?[package:][type:]name"(主题属性)的格式来指向某个包含此类型值的资源。
这个属性需要配合addFooterView这个方法使用,此属性缺省值为true。这个属性只对页脚起作用,如果listview中没有添加页脚这个属性就不起作用。
其方法列表如下:
<nobr>void</nobr> |
<nobr><span class="sympad" style="margin-right:2px"><a href="http://developer.android.com/reference/android/widget/ListView.html#addFooterView(android.view.View)" style="color:rgb(0,102,153); text-decoration:none">addFooterView</a></span>(<a href="http://developer.android.com/reference/android/view/View.html" style="color:rgb(0,102,153); text-decoration:none">View</a>v)</nobr>
Add a fixed view to appear at the bottom of the list.
|
<nobr>void</nobr> |
<nobr><span class="sympad" style="margin-right:2px"><a href="http://developer.android.com/reference/android/widget/ListView.html#addFooterView(android.view.View,%20java.lang.Object,%20boolean)" style="color:rgb(0,102,153); text-decoration:none">addFooterView</a></span>(<a href="http://developer.android.com/reference/android/view/View.html" style="color:rgb(0,102,153); text-decoration:none">View</a>v,<a href="http://developer.android.com/reference/java/lang/Object.html" style="color:rgb(0,102,153); text-decoration:none">Object</a>data,
boolean isSelectable)</nobr>
Add a fixed view to appear at the bottom of the list.
|
<nobr>void</nobr> |
<nobr><span class="sympad" style="margin-right:2px"><a href="http://developer.android.com/reference/android/widget/ListView.html#addHeaderView(android.view.View,%20java.lang.Object,%20boolean)" style="color:rgb(0,102,153); text-decoration:none">addHeaderView</a></span>(<a href="http://developer.android.com/reference/android/view/View.html" style="color:rgb(0,102,153); text-decoration:none">View</a>v,<a href="http://developer.android.com/reference/java/lang/Object.html" style="color:rgb(0,102,153); text-decoration:none">Object</a>data,
boolean isSelectable)</nobr>
Add a fixed view to appear at the top of the list.
|
<nobr>void</nobr> |
<nobr><span class="sympad" style="margin-right:2px"><a href="http://developer.android.com/reference/android/widget/ListView.html#addHeaderView(android.view.View)" style="color:rgb(0,102,153); text-decoration:none">addHeaderView</a></span>(<a href="http://developer.android.com/reference/android/view/View.html" style="color:rgb(0,102,153); text-decoration:none">View</a>v)</nobr>
Add a fixed view to appear at the top of the list.
|
<nobr>boolean</nobr> |
<nobr><span class="sympad" style="margin-right:2px"><a href="http://developer.android.com/reference/android/widget/ListView.html#dispatchKeyEvent(android.view.KeyEvent)" style="color:rgb(0,102,153); text-decoration:none">dispatchKeyEvent</a></span>(<a href="http://developer.android.com/reference/android/view/KeyEvent.html" style="color:rgb(0,102,153); text-decoration:none">KeyEvent</a>event)</nobr>
Dispatch a key event to the next view on the focus path.
|
<nobr><a href="http://developer.android.com/reference/android/widget/ListAdapter.html" style="color:rgb(0,102,153); text-decoration:none">ListAdapter</a></nobr> |
<nobr><span class="sympad" style="margin-right:2px"><a href="http://developer.android.com/reference/android/widget/ListView.html#getAdapter()" style="color:rgb(0,102,153); text-decoration:none">getAdapter</a></span>()</nobr>
Returns the adapter currently in use in this ListView.
|
<nobr>long[]</nobr> |
<nobr><span class="sympad" style="margin-right:2px"><a href="http://developer.android.com/reference/android/widget/ListView.html#getCheckItemIds()" style="color:rgb(0,102,153); text-decoration:none">getCheckItemIds</a></span>()</nobr>
This method is deprecated. Use
getCheckedItemIds() instead.
|
<nobr><a href="http://developer.android.com/reference/android/graphics/drawable/Drawable.html" style="color:rgb(0,102,153); text-decoration:none">Drawable</a></nobr> |
<nobr><span class="sympad" style="margin-right:2px"><a href="http://developer.android.com/reference/android/widget/ListView.html#getDivider()" style="color:rgb(0,102,153); text-decoration:none">getDivider</a></span>()</nobr>
Returns the drawable that will be drawn between each item in the list.
|
<nobr>int</nobr> | <nobr><span class="sympad" style="margin-right:2px"><a href="http://developer.android.com/reference/android/widget/ListView.html#getDividerHeight()" style="color:rgb(0,102,153); text-decoration:none">getDividerHeight</a></span>()</nobr> |
<nobr>int</nobr> |
<nobr><span class="sympad" style="margin-right:2px"><a href="http://developer.android.com/reference/android/widget/ListView.html#getFooterViewsCount()" style="color:rgb(0,102,153); text-decoration:none">getFooterViewsCount</a></span>()</nobr>
Returns the number of footer views in the list.
|
<nobr>int</nobr> |
<nobr><span class="sympad" style="margin-right:2px"><a href="http://developer.android.com/reference/android/widget/ListView.html#getHeaderViewsCount()" style="color:rgb(0,102,153); text-decoration:none">getHeaderViewsCount</a></span>()</nobr>
Returns the number of header views in the list.
|
<nobr>boolean</nobr> | <nobr><span class="sympad" style="margin-right:2px"><a href="http://developer.android.com/reference/android/widget/ListView.html#getItemsCanFocus()" style="color:rgb(0,102,153); text-decoration:none">getItemsCanFocus</a></span>()</nobr> |
<nobr>int</nobr> | <nobr><span class="sympad" style="margin-right:2px"><a href="http://developer.android.com/reference/android/widget/ListView.html#getMaxScrollAmount()" style="color:rgb(0,102,153); text-decoration:none">getMaxScrollAmount</a></span>()</nobr> |
<nobr><a href="http://developer.android.com/reference/android/graphics/drawable/Drawable.html" style="color:rgb(0,102,153); text-decoration:none">Drawable</a></nobr> | <nobr><span class="sympad" style="margin-right:2px"><a href="http://developer.android.com/reference/android/widget/ListView.html#getOverscrollFooter()" style="color:rgb(0,102,153); text-decoration:none">getOverscrollFooter</a></span>()</nobr> |
<nobr><a href="http://developer.android.com/reference/android/graphics/drawable/Drawable.html" style="color:rgb(0,102,153); text-decoration:none">Drawable</a></nobr> | <nobr><span class="sympad" style="margin-right:2px"><a href="http://developer.android.com/reference/android/widget/ListView.html#getOverscrollHeader()" style="color:rgb(0,102,153); text-decoration:none">getOverscrollHeader</a></span>()</nobr> |
<nobr>boolean</nobr> |
<nobr><span class="sympad" style="margin-right:2px"><a href="http://developer.android.com/reference/android/widget/ListView.html#isOpaque()" style="color:rgb(0,102,153); text-decoration:none">isOpaque</a></span>()</nobr>
Indicates whether this View is opaque.
|
<nobr>boolean</nobr> |
<nobr><span class="sympad" style="margin-right:2px"><a href="http://developer.android.com/reference/android/widget/ListView.html#onKeyDown(int,%20android.view.KeyEvent)" style="color:rgb(0,102,153); text-decoration:none">onKeyDown</a></span>(int keyCode,<a href="http://developer.android.com/reference/android/view/KeyEvent.html" style="color:rgb(0,102,153); text-decoration:none">KeyEvent</a>event)</nobr>
Default implementation of
KeyEvent.Callback.onKeyDown() :
perform press of the view whenKEYCODE_DPAD_CENTER orKEYCODE_ENTER is
released, if the view is enabled and clickable. |
<nobr>boolean</nobr> |
<nobr><span class="sympad" style="margin-right:2px"><a href="http://developer.android.com/reference/android/widget/ListView.html#onKeyMultiple(int,%20int,%20android.view.KeyEvent)" style="color:rgb(0,102,153); text-decoration:none">onKeyMultiple</a></span>(int
keyCode, int repeatCount,<a href="http://developer.android.com/reference/android/view/KeyEvent.html" style="color:rgb(0,102,153); text-decoration:none">KeyEvent</a>event)</nobr>
Default implementation of
KeyEvent.Callback.onKeyMultiple() :
always returns false (doesn't handle the event). |
<nobr>boolean</nobr> |
<nobr><span class="sympad" style="margin-right:2px"><a href="http://developer.android.com/reference/android/widget/ListView.html#onKeyUp(int,%20android.view.KeyEvent)" style="color:rgb(0,102,153); text-decoration:none">onKeyUp</a></span>(int keyCode,<a href="http://developer.android.com/reference/android/view/KeyEvent.html" style="color:rgb(0,102,153); text-decoration:none">KeyEvent</a>event)</nobr>
Default implementation of
KeyEvent.Callback.onKeyUp() :
perform clicking of the view whenKEYCODE_DPAD_CENTER orKEYCODE_ENTER is
released. |
<nobr>boolean</nobr> |
<nobr><span class="sympad" style="margin-right:2px"><a href="http://developer.android.com/reference/android/widget/ListView.html#removeFooterView(android.view.View)" style="color:rgb(0,102,153); text-decoration:none">removeFooterView</a></span>(<a href="http://developer.android.com/reference/android/view/View.html" style="color:rgb(0,102,153); text-decoration:none">View</a>v)</nobr>
Removes a previously-added footer view.
|
<nobr>boolean</nobr> |
<nobr><span class="sympad" style="margin-right:2px"><a href="http://developer.android.com/reference/android/widget/ListView.html#removeHeaderView(android.view.View)" style="color:rgb(0,102,153); text-decoration:none">removeHeaderView</a></span>(<a href="http://developer.android.com/reference/android/view/View.html" style="color:rgb(0,102,153); text-decoration:none">View</a>v)</nobr>
Removes a previously-added header view.
|
<nobr>boolean</nobr> |
<nobr><span class="sympad" style="margin-right:2px"><a href="http://developer.android.com/reference/android/widget/ListView.html#requestChildRectangleOnScreen(android.view.View,%20android.graphics.Rect,%20boolean)" style="color:rgb(0,102,153); text-decoration:none">requestChildRectangleOnScreen</a></span>(<a href="http://developer.android.com/reference/android/view/View.html" style="color:rgb(0,102,153); text-decoration:none">View</a>child,<a href="http://developer.android.com/reference/android/graphics/Rect.html" style="color:rgb(0,102,153); text-decoration:none">Rect</a>rect,
boolean immediate)</nobr>
Called when a child of this group wants a particular rectangle to be positioned onto the screen.
|
<nobr>void</nobr> |
<nobr><span class="sympad" style="margin-right:2px"><a href="http://developer.android.com/reference/android/widget/ListView.html#setAdapter(android.widget.ListAdapter)" style="color:rgb(0,102,153); text-decoration:none">setAdapter</a></span>(<a href="http://developer.android.com/reference/android/widget/ListAdapter.html" style="color:rgb(0,102,153); text-decoration:none">ListAdapter</a>adapter)</nobr>
Sets the data behind this ListView.
|
<nobr>void</nobr> |
<nobr><span class="sympad" style="margin-right:2px"><a href="http://developer.android.com/reference/android/widget/ListView.html#setCacheColorHint(int)" style="color:rgb(0,102,153); text-decoration:none">setCacheColorHint</a></span>(int color)</nobr>
When set to a non-zero value, the cache color hint indicates that this list is always drawn on top of a solid, single-color, opaque background.
|
<nobr>void</nobr> |
<nobr><span class="sympad" style="margin-right:2px"><a href="http://developer.android.com/reference/android/widget/ListView.html#setDivider(android.graphics.drawable.Drawable)" style="color:rgb(0,102,153); text-decoration:none">setDivider</a></span>(<a href="http://developer.android.com/reference/android/graphics/drawable/Drawable.html" style="color:rgb(0,102,153); text-decoration:none">Drawable</a>divider)</nobr>
Sets the drawable that will be drawn between each item in the list.
|
<nobr>void</nobr> |
<nobr><span class="sympad" style="margin-right:2px"><a href="http://developer.android.com/reference/android/widget/ListView.html#setDividerHeight(int)" style="color:rgb(0,102,153); text-decoration:none">setDividerHeight</a></span>(int height)</nobr>
Sets the height of the divider that will be drawn between each item in the list.
|
<nobr>void</nobr> |
<nobr><span class="sympad" style="margin-right:2px"><a href="http://developer.android.com/reference/android/widget/ListView.html#setFooterDividersEnabled(boolean)" style="color:rgb(0,102,153); text-decoration:none">setFooterDividersEnabled</a></span>(boolean
footerDividersEnabled)</nobr>
Enables or disables the drawing of the divider for footer views.
|
<nobr>void</nobr> |
<nobr><span class="sympad" style="margin-right:2px"><a href="http://developer.android.com/reference/android/widget/ListView.html#setHeaderDividersEnabled(boolean)" style="color:rgb(0,102,153); text-decoration:none">setHeaderDividersEnabled</a></span>(boolean
headerDividersEnabled)</nobr>
Enables or disables the drawing of the divider for header views.
|
<nobr>void</nobr> |
<nobr><span class="sympad" style="margin-right:2px"><a href="http://developer.android.com/reference/android/widget/ListView.html#setItemsCanFocus(boolean)" style="color:rgb(0,102,153); text-decoration:none">setItemsCanFocus</a></span>(boolean itemsCanFocus)</nobr>
Indicates that the views created by the ListAdapter can contain focusable items.
|
<nobr>void</nobr> |
<nobr><span class="sympad" style="margin-right:2px"><a href="http://developer.android.com/reference/android/widget/ListView.html#setOverscrollFooter(android.graphics.drawable.Drawable)" style="color:rgb(0,102,153); text-decoration:none">setOverscrollFooter</a></span>(<a href="http://developer.android.com/reference/android/graphics/drawable/Drawable.html" style="color:rgb(0,102,153); text-decoration:none">Drawable</a>footer)</nobr>
Sets the drawable that will be drawn below all other list content.
|
<nobr>void</nobr> |
<nobr><span class="sympad" style="margin-right:2px"><a href="http://developer.android.com/reference/android/widget/ListView.html#setOverscrollHeader(android.graphics.drawable.Drawable)" style="color:rgb(0,102,153); text-decoration:none">setOverscrollHeader</a></span>(<a href="http://developer.android.com/reference/android/graphics/drawable/Drawable.html" style="color:rgb(0,102,153); text-decoration:none">Drawable</a>header)</nobr>
Sets the drawable that will be drawn above all other list content.
|
<nobr>void</nobr> |
<nobr><span class="sympad" style="margin-right:2px"><a href="http://developer.android.com/reference/android/widget/ListView.html#setRemoteViewsAdapter(android.content.Intent)" style="color:rgb(0,102,153); text-decoration:none">setRemoteViewsAdapter</a></span>(<a href="http://developer.android.com/reference/android/content/Intent.html" style="color:rgb(0,102,153); text-decoration:none">Intent</a>intent)</nobr>
Sets up this AbsListView to use a remote views adapter which connects to a RemoteViewsService through the specified intent.
|
<nobr>void</nobr> |
<nobr><span class="sympad" style="margin-right:2px"><a href="http://developer.android.com/reference/android/widget/ListView.html#setSelection(int)" style="color:rgb(0,102,153); text-decoration:none">setSelection</a></span>(int position)</nobr>
Sets the currently selected item.
|
<nobr>void</nobr> |
<nobr><span class="sympad" style="margin-right:2px"><a href="http://developer.android.com/reference/android/widget/ListView.html#setSelectionAfterHeaderView()" style="color:rgb(0,102,153); text-decoration:none">setSelectionAfterHeaderView</a></span>()</nobr>
setSelectionAfterHeaderView set the selection to be the first list item after the header views.
|
<nobr>void</nobr> |
<nobr><span class="sympad" style="margin-right:2px"><a href="http://developer.android.com/reference/android/widget/ListView.html#setSelectionFromTop(int,%20int)" style="color:rgb(0,102,153); text-decoration:none">setSelectionFromTop</a></span>(int position, int
y)</nobr>
Sets the selected item and positions the selection y pixels from the top edge of the ListView.
|
<nobr>void</nobr> |
<nobr><span class="sympad" style="margin-right:2px"><a href="http://developer.android.com/reference/android/widget/ListView.html#smoothScrollByOffset(int)" style="color:rgb(0,102,153); text-decoration:none">smoothScrollByOffset</a></span>(int offset)</nobr>
Smoothly scroll to the specified adapter position offset.
|
<nobr>void</nobr> |
<nobr><span class="sympad" style="margin-right:2px"><a href="http://developer.android.com/reference/android/widget/ListView.html#smoothScrollToPosition(int)" style="color:rgb(0,102,153); text-decoration:none">smoothScrollToPosition</a></span>(int position)</nobr>
Smoothly scroll to the specified adapter position.
|
当listView定长滑动时,顶端会出现黑边,影响效果,可以使用setCacheColorHint(0)这个方法。其他的方法,直接从字面意思上大体就可以明白的差不多,不多说了。
常遇到的问题及方法:
1.、listview在拖动的时候背景图片消失变成黑色背景。等到拖动完毕我们自己的背景图片才显示出来。
2、listview的上边和下边有黑色的阴影。
3、lsitview的每一项之间需要设置一个图片做为间隔。
针对以上问题 在listview的xml文件中设置一下语句。
问题1 有如下代码结解决android:scrollingCache="false"
问题2 用如下代码解决:android:fadingEdge="none"
问题3用如下代码解决:android:divider="@drawable/list_driver" 其中 @drawable/list_driver 是一个图片资源
总体如下
以上三个问题均来自网络。当然,也可以在java代码中使用方法来解决,上面都有提及,如setDivider()、setCacheColorHint(0)等。
相关推荐
Android开发中listview属性的介绍
ListView控件属性、方法、事件ListView控件属性、方法、事件ListView控件属性、方法、事件
listview的属性和方法的应用实例!
ListView控件比前面几种控件要复杂一些,通过此控件,可将项目组成带有或不带有列标头的列,并显示伴随的图标和文本。ListView控件是由ColumnHeader和ListItem对象所组成的,其中ColumnHeader对象的个数决定了控件的...
ListView属性AddObject实例
android listview 非常全面属性的,希望对你们有所帮助!
.net下 ListView_控件属性与方法
VB编程的LISTVIEW空间的详细用法与属性介绍
c# listview 使用方法c# listview 使用方法c# listview 使用方法c# listview 使用方法c# listview 使用方法c# listview 使用方法c# listview 使用方法c# listview 使用方法c# listview 使用方法c# listview 使用方法...
把android中重要的listview的用法进行归纳总结
主要介绍了Delphi控件ListView的属性及使用方法详解,对于Delphi控件ListView做一复习总结,需要的朋友可以参考下
ListView属性用法介绍android.pdf
android listview的使用方法,最简单的listview使用。
文档介绍了EXCEL VBA中Listview控件常用方法,Listview控件功能较之list控件强大很多,可多列显示。
C#从datatable到listview的方法
含2个listview分组demo,区别在于是否进行折叠分组
ListView适配器及缓存机制
android自定义listview使用方法 提供一般listview 带图片的listview 带按钮的listview listview学习的好Demo
主要实现通过几种不同的适配器实现listview