Android开发 - 下拉刷新和分段头悬停列表

目录(?)[+]

项目源码

本文所述项目已开源,源码地址

为什么做PullToRefresh-PinnedSection-ListView

前段时间因为项目需求,需要在Android中对ListView同时增加下拉刷新和分段头悬停的效果,受到dkmeteor的启发,Merge了两个Github上的开源项目:

  • Android-PullToRefresh(handmark版,目前已不再更新)

  • StickyListHeaders(目前版本为2.x)

    由于既有项目里的StickyListHeaders代码为1.x版本,StickyListHeadersListView继承自ListView,故与handmark版的PullToRefreshListView做merge时很顺畅;

    但2.x版的StickyListHeadersListView继承自FrameLayout,与PullToRefresh的融合并不顺利,若要整理拆分出一个独立的lib时遇到很多的问题,故在分断头悬停需求上采用了另一个类似的开源项目:

  • pinned-section-listview

我是如何做的

前面已经介绍过这个过程是“很顺畅”的:

1.Library方面,基于PullToRefresh的Library修改,首先使其依赖StickyListHeaders的Library,通过拷贝src/com/handmark/pulltorefresh/library/PullToRefreshListView.java类,新建PullToRefreshPinnedSectionListView.java类;

2.修改PullToRefreshPinnedSectionListView类中createListView()方法,注释以下代码

<div class="line"><span class="text plain"><span class="meta paragraph text"></span></span></div><div class="dp-highlighter bg_java" style="font-family: Consolas, 'Courier New', Courier, mono, serif; font-size: 12px; width: 938.516px; overflow: hidden; padding-top: 1px; border-color: rgb(204, 204, 204); background-color: rgb(231, 229, 220); margin: 18px 0px !important;"><div class="bar" style="padding-left: 45px;"><div class="tools" style="padding: 3px 8px 10px 10px; font-size: 9px; line-height: normal; font-family: Verdana, Geneva, Arial, Helvetica, sans-serif; color: silver; border-left-width: 3px; border-left-style: solid; border-left-color: rgb(153, 153, 153); background-color: rgb(248, 248, 248);"><strong>[java]</strong> <a target=_blank href="http://blog.csdn.net/tongcpp/article/details/40372521#" class="ViewSource" title="view plain" style="text-decoration: none; border: none; padding: 0px; margin: 0px 10px 0px 0px; color: rgb(12, 137, 207); background-image: none; background-color: inherit; background-position: initial initial; background-repeat: initial initial;">view plain</a><a target=_blank href="http://blog.csdn.net/tongcpp/article/details/40372521#" class="CopyToClipboard" title="copy" style="text-decoration: none; border: none; padding: 0px; margin: 0px 10px 0px 0px; color: rgb(12, 137, 207); background-image: none; background-color: inherit; background-position: initial initial; background-repeat: initial initial;">copy</a><a target=_blank href="http://blog.csdn.net/tongcpp/article/details/40372521#" class="PrintSource" title="print" style="text-decoration: none; border: none; padding: 0px; margin: 0px 10px 0px 0px; color: rgb(12, 137, 207); background-image: none; background-color: inherit; background-position: initial initial; background-repeat: initial initial;">print</a><a target=_blank href="http://blog.csdn.net/tongcpp/article/details/40372521#" class="About" title="?" style="text-decoration: none; border: none; padding: 0px; margin: 0px 10px 0px 0px; color: rgb(12, 137, 207); background-image: none; background-color: inherit; background-position: initial initial; background-repeat: initial initial;">?</a><a target=_blank href="https://code.csdn.net/snippets/492335" target="_blank" title="在CODE上查看代码片" style="text-decoration: none; border: none; padding: 0px; margin: 0px 10px 0px 0px; color: rgb(12, 137, 207); background-image: none; background-color: inherit; background-position: initial initial; background-repeat: initial initial;"><img src="https://code.csdn.net/assets/CODE_ico.png" width="12" height="12" alt="在CODE上查看代码片" style="border: none; position: relative; top: 1px; left: 2px;" /></a><a target=_blank href="https://code.csdn.net/snippets/492335/fork" target="_blank" title="派生到我的代码片" style="text-decoration: none; border: none; padding: 0px; margin: 0px 10px 0px 0px; color: rgb(12, 137, 207); background-image: none; background-color: inherit; background-position: initial initial; background-repeat: initial initial;"><img src="https://code.csdn.net/assets/ico_fork.svg" width="12" height="12" alt="派生到我的代码片" style="border: none; position: relative; top: 2px; left: 2px;" /></a><div style="position: absolute; left: 558px; top: 1342px; width: 29px; height: 15px; z-index: 99;"><embed id="ZeroClipboardMovie_1" src="http://static.blog.csdn.net/scripts/ZeroClipboard/ZeroClipboard.swf" loop="false" menu="false" quality="best" bgcolor="#ffffff" width="29" height="15" name="ZeroClipboardMovie_1" align="middle" allowscriptaccess="always" allowfullscreen="false" type="application/x-shockwave-flash" pluginspage="http://www.macromedia.com/go/getflashplayer" flashvars="id=1&width=29&height=15" wmode="transparent" style="animation-duration: 0.001s; animation-name: playerInserted;" /></div></div></div><ol start="1" class="dp-j" style="padding: 0px; border: none; list-style-position: initial; list-style-image: initial; color: rgb(92, 92, 92); background-color: rgb(255, 255, 255); margin: 0px 0px 1px 45px !important;"><li class="alt" style="border-style: none none none solid; border-left-width: 3px; border-left-color: rgb(153, 153, 153); list-style: decimal-leading-zero outside; color: inherit; line-height: 18px; margin: 0px !important; padding: 0px 3px 0px 10px !important;"><span style="margin: 0px; padding: 0px; border: none; color: black; background-color: inherit;"><span class="comment" style="margin: 0px; padding: 0px; border: none; color: rgb(170, 202, 179); background-color: inherit;">//        if (VERSION.SDK_INT >= VERSION_CODES.GINGERBREAD) {</span><span style="margin: 0px; padding: 0px; border: none; background-color: inherit;">  </span></span></li><li style="margin: 0px !important; padding: 0px 3px 0px 10px !important; border-style: none none none solid; border-left-width: 3px; border-left-color: rgb(153, 153, 153); list-style: decimal-leading-zero outside; color: rgb(119, 119, 119); line-height: 18px; background-color: rgb(249, 249, 249);"><span style="margin: 0px; padding: 0px; border: none; color: black; background-color: inherit;"><span class="comment" style="margin: 0px; padding: 0px; border: none; color: rgb(170, 202, 179); background-color: inherit;">//            lv = new InternalListViewSDK9(context, attrs);</span><span style="margin: 0px; padding: 0px; border: none; background-color: inherit;">  </span></span></li><li class="alt" style="border-style: none none none solid; border-left-width: 3px; border-left-color: rgb(153, 153, 153); list-style: decimal-leading-zero outside; color: inherit; line-height: 18px; margin: 0px !important; padding: 0px 3px 0px 10px !important;"><span style="margin: 0px; padding: 0px; border: none; color: black; background-color: inherit;"><span class="comment" style="margin: 0px; padding: 0px; border: none; color: rgb(170, 202, 179); background-color: inherit;">//        } else {</span><span style="margin: 0px; padding: 0px; border: none; background-color: inherit;">  </span></span></li><li style="margin: 0px !important; padding: 0px 3px 0px 10px !important; border-style: none none none solid; border-left-width: 3px; border-left-color: rgb(153, 153, 153); list-style: decimal-leading-zero outside; color: rgb(119, 119, 119); line-height: 18px; background-color: rgb(249, 249, 249);"><span style="margin: 0px; padding: 0px; border: none; color: black; background-color: inherit;"><span class="comment" style="margin: 0px; padding: 0px; border: none; color: rgb(170, 202, 179); background-color: inherit;">//            lv = new InternalListView(context, attrs);</span><span style="margin: 0px; padding: 0px; border: none; background-color: inherit;">  </span></span></li><li class="alt" style="border-style: none none none solid; border-left-width: 3px; border-left-color: rgb(153, 153, 153); list-style: decimal-leading-zero outside; color: inherit; line-height: 18px; margin: 0px !important; padding: 0px 3px 0px 10px !important;"><span style="margin: 0px; padding: 0px; border: none; color: black; background-color: inherit;"><span class="comment" style="margin: 0px; padding: 0px; border: none; color: rgb(170, 202, 179); background-color: inherit;">//        }</span><span style="margin: 0px; padding: 0px; border: none; background-color: inherit;">  </span></span></li></ol></div>
<div class="line"><span class="text plain"><span class="meta paragraph text"></span></span></div>

添加

<div class="line"><span class="text plain"><span class="meta paragraph text"></span></span><div class="dp-highlighter bg_java" style="font-family: Consolas, 'Courier New', Courier, mono, serif; font-size: 12px; width: 938.516px; overflow: hidden; padding-top: 1px; border-color: rgb(204, 204, 204); background-color: rgb(231, 229, 220); margin: 18px 0px !important;"><div class="bar" style="padding-left: 45px;"><div class="tools" style="padding: 3px 8px 10px 10px; font-size: 9px; line-height: normal; font-family: Verdana, Geneva, Arial, Helvetica, sans-serif; color: silver; border-left-width: 3px; border-left-style: solid; border-left-color: rgb(153, 153, 153); background-color: rgb(248, 248, 248);"><strong>[java]</strong> <a target=_blank href="http://blog.csdn.net/tongcpp/article/details/40372521#" class="ViewSource" title="view plain" style="text-decoration: none; border: none; padding: 0px; margin: 0px 10px 0px 0px; color: rgb(12, 137, 207); background-image: none; background-color: inherit; background-position: initial initial; background-repeat: initial initial;">view plain</a><a target=_blank href="http://blog.csdn.net/tongcpp/article/details/40372521#" class="CopyToClipboard" title="copy" style="text-decoration: none; border: none; padding: 0px; margin: 0px 10px 0px 0px; color: rgb(12, 137, 207); background-image: none; background-color: inherit; background-position: initial initial; background-repeat: initial initial;">copy</a><a target=_blank href="http://blog.csdn.net/tongcpp/article/details/40372521#" class="PrintSource" title="print" style="text-decoration: none; border: none; padding: 0px; margin: 0px 10px 0px 0px; color: rgb(12, 137, 207); background-image: none; background-color: inherit; background-position: initial initial; background-repeat: initial initial;">print</a><a target=_blank href="http://blog.csdn.net/tongcpp/article/details/40372521#" class="About" title="?" style="text-decoration: none; border: none; padding: 0px; margin: 0px 10px 0px 0px; color: rgb(12, 137, 207); background-image: none; background-color: inherit; background-position: initial initial; background-repeat: initial initial;">?</a><a target=_blank href="https://code.csdn.net/snippets/492335" target="_blank" title="在CODE上查看代码片" style="text-decoration: none; border: none; padding: 0px; margin: 0px 10px 0px 0px; color: rgb(12, 137, 207); background-image: none; background-color: inherit; background-position: initial initial; background-repeat: initial initial;"><img src="https://code.csdn.net/assets/CODE_ico.png" width="12" height="12" alt="在CODE上查看代码片" style="border: none; position: relative; top: 1px; left: 2px;" /></a><a target=_blank href="https://code.csdn.net/snippets/492335/fork" target="_blank" title="派生到我的代码片" style="text-decoration: none; border: none; padding: 0px; margin: 0px 10px 0px 0px; color: rgb(12, 137, 207); background-image: none; background-color: inherit; background-position: initial initial; background-repeat: initial initial;"><img src="https://code.csdn.net/assets/ico_fork.svg" width="12" height="12" alt="派生到我的代码片" style="border: none; position: relative; top: 2px; left: 2px;" /></a><div style="position: absolute; left: 558px; top: 1583px; width: 29px; height: 15px; z-index: 99;"><embed id="ZeroClipboardMovie_2" src="http://static.blog.csdn.net/scripts/ZeroClipboard/ZeroClipboard.swf" loop="false" menu="false" quality="best" bgcolor="#ffffff" width="29" height="15" name="ZeroClipboardMovie_2" align="middle" allowscriptaccess="always" allowfullscreen="false" type="application/x-shockwave-flash" pluginspage="http://www.macromedia.com/go/getflashplayer" flashvars="id=2&width=29&height=15" wmode="transparent" style="animation-duration: 0.001s; animation-name: playerInserted;" /></div></div></div><ol start="1" class="dp-j" style="padding: 0px; border: none; list-style-position: initial; list-style-image: initial; color: rgb(92, 92, 92); background-color: rgb(255, 255, 255); margin: 0px 0px 1px 45px !important;"><li class="alt" style="border-style: none none none solid; border-left-width: 3px; border-left-color: rgb(153, 153, 153); list-style: decimal-leading-zero outside; color: inherit; line-height: 18px; margin: 0px !important; padding: 0px 3px 0px 10px !important;"><span style="margin: 0px; padding: 0px; border: none; color: black; background-color: inherit;"><span style="margin: 0px; padding: 0px; border: none; background-color: inherit;">lv = </span><span class="keyword" style="margin: 0px; padding: 0px; border: none; color: green; font-weight: bold; background-color: inherit;">new</span><span style="margin: 0px; padding: 0px; border: none; background-color: inherit;"> PinnedSectionListView(context, attrs);  </span></span></li></ol></div>
</div>

3.Example方面,基于pinned-section-listview的example修改,令其依赖PullToRefresh的Library;

4.修改主类资源文件activity_main.xml,设置List组件为新类:

<div class="line"><span class="text plain"><span class="meta paragraph text"></span></span></div><div class="dp-highlighter bg_html" style="font-family: Consolas, 'Courier New', Courier, mono, serif; font-size: 12px; width: 938.516px; overflow: hidden; padding-top: 1px; border-color: rgb(204, 204, 204); background-color: rgb(231, 229, 220); margin: 18px 0px !important;"><div class="bar" style="padding-left: 45px;"><div class="tools" style="padding: 3px 8px 10px 10px; font-size: 9px; line-height: normal; font-family: Verdana, Geneva, Arial, Helvetica, sans-serif; color: silver; border-left-width: 3px; border-left-style: solid; border-left-color: rgb(153, 153, 153); background-color: rgb(248, 248, 248);"><strong>[html]</strong> <a target=_blank href="http://blog.csdn.net/tongcpp/article/details/40372521#" class="ViewSource" title="view plain" style="text-decoration: none; border: none; padding: 0px; margin: 0px 10px 0px 0px; color: rgb(12, 137, 207); background-image: none; background-color: inherit; background-position: initial initial; background-repeat: initial initial;">view plain</a><a target=_blank href="http://blog.csdn.net/tongcpp/article/details/40372521#" class="CopyToClipboard" title="copy" style="text-decoration: none; border: none; padding: 0px; margin: 0px 10px 0px 0px; color: rgb(12, 137, 207); background-image: none; background-color: inherit; background-position: initial initial; background-repeat: initial initial;">copy</a><a target=_blank href="http://blog.csdn.net/tongcpp/article/details/40372521#" class="PrintSource" title="print" style="text-decoration: none; border: none; padding: 0px; margin: 0px 10px 0px 0px; color: rgb(12, 137, 207); background-image: none; background-color: inherit; background-position: initial initial; background-repeat: initial initial;">print</a><a target=_blank href="http://blog.csdn.net/tongcpp/article/details/40372521#" class="About" title="?" style="text-decoration: none; border: none; padding: 0px; margin: 0px 10px 0px 0px; color: rgb(12, 137, 207); background-image: none; background-color: inherit; background-position: initial initial; background-repeat: initial initial;">?</a><a target=_blank href="https://code.csdn.net/snippets/492335" target="_blank" title="在CODE上查看代码片" style="text-decoration: none; border: none; padding: 0px; margin: 0px 10px 0px 0px; color: rgb(12, 137, 207); background-image: none; background-color: inherit; background-position: initial initial; background-repeat: initial initial;"><img src="https://code.csdn.net/assets/CODE_ico.png" width="12" height="12" alt="在CODE上查看代码片" style="border: none; position: relative; top: 1px; left: 2px;" /></a><a target=_blank href="https://code.csdn.net/snippets/492335/fork" target="_blank" title="派生到我的代码片" style="text-decoration: none; border: none; padding: 0px; margin: 0px 10px 0px 0px; color: rgb(12, 137, 207); background-image: none; background-color: inherit; background-position: initial initial; background-repeat: initial initial;"><img src="https://code.csdn.net/assets/ico_fork.svg" width="12" height="12" alt="派生到我的代码片" style="border: none; position: relative; top: 2px; left: 2px;" /></a><div style="position: absolute; left: 560px; top: 1787px; width: 29px; height: 15px; z-index: 99;"><embed id="ZeroClipboardMovie_3" src="http://static.blog.csdn.net/scripts/ZeroClipboard/ZeroClipboard.swf" loop="false" menu="false" quality="best" bgcolor="#ffffff" width="29" height="15" name="ZeroClipboardMovie_3" align="middle" allowscriptaccess="always" allowfullscreen="false" type="application/x-shockwave-flash" pluginspage="http://www.macromedia.com/go/getflashplayer" flashvars="id=3&width=29&height=15" wmode="transparent" style="animation-duration: 0.001s; animation-name: playerInserted;" /></div></div></div><ol start="1" class="dp-xml" style="padding: 0px; border: none; list-style-position: initial; list-style-image: initial; color: rgb(92, 92, 92); background-color: rgb(255, 255, 255); margin: 0px 0px 1px 45px !important;"><li class="alt" style="border-style: none none none solid; border-left-width: 3px; border-left-color: rgb(153, 153, 153); list-style: decimal-leading-zero outside; color: inherit; line-height: 18px; margin: 0px !important; padding: 0px 3px 0px 10px !important;"><span style="margin: 0px; padding: 0px; border: none; color: black; background-color: inherit;"><span class="tag" style="margin: 0px; padding: 0px; border: none; color: green; font-weight: bold; background-color: inherit;"><</span><span class="tag-name" style="margin: 0px; padding: 0px; border: none; color: green; font-weight: bold; background-color: inherit;">com.handmark.pulltorefresh.library.PullToRefreshPinnedSectionListView</span><span style="margin: 0px; padding: 0px; border: none; background-color: inherit;"> </span><span class="attribute" style="margin: 0px; padding: 0px; border: none; color: red; background-color: inherit;">xmlns:android</span><span style="margin: 0px; padding: 0px; border: none; background-color: inherit;">=</span><span class="attribute-value" style="margin: 0px; padding: 0px; border: none; background-color: inherit;">"http://schemas.android.com/apk/res/android"</span><span style="margin: 0px; padding: 0px; border: none; background-color: inherit;">  </span></span></li><li style="margin: 0px !important; padding: 0px 3px 0px 10px !important; border-style: none none none solid; border-left-width: 3px; border-left-color: rgb(153, 153, 153); list-style: decimal-leading-zero outside; color: rgb(119, 119, 119); line-height: 18px; background-color: rgb(249, 249, 249);"><span style="margin: 0px; padding: 0px; border: none; color: black; background-color: inherit;"><span class="attribute" style="margin: 0px; padding: 0px; border: none; color: red; background-color: inherit;">android:id</span><span style="margin: 0px; padding: 0px; border: none; background-color: inherit;">=</span><span class="attribute-value" style="margin: 0px; padding: 0px; border: none; background-color: inherit;">"@+id/list"</span><span style="margin: 0px; padding: 0px; border: none; background-color: inherit;">  </span></span></li><li class="alt" style="border-style: none none none solid; border-left-width: 3px; border-left-color: rgb(153, 153, 153); list-style: decimal-leading-zero outside; color: inherit; line-height: 18px; margin: 0px !important; padding: 0px 3px 0px 10px !important;"><span style="margin: 0px; padding: 0px; border: none; color: black; background-color: inherit;"><span class="attribute" style="margin: 0px; padding: 0px; border: none; color: red; background-color: inherit;">android:layout_width</span><span style="margin: 0px; padding: 0px; border: none; background-color: inherit;">=</span><span class="attribute-value" style="margin: 0px; padding: 0px; border: none; background-color: inherit;">"match_parent"</span><span style="margin: 0px; padding: 0px; border: none; background-color: inherit;">  </span></span></li><li style="margin: 0px !important; padding: 0px 3px 0px 10px !important; border-style: none none none solid; border-left-width: 3px; border-left-color: rgb(153, 153, 153); list-style: decimal-leading-zero outside; color: rgb(119, 119, 119); line-height: 18px; background-color: rgb(249, 249, 249);"><span style="margin: 0px; padding: 0px; border: none; color: black; background-color: inherit;"><span class="attribute" style="margin: 0px; padding: 0px; border: none; color: red; background-color: inherit;">android:layout_height</span><span style="margin: 0px; padding: 0px; border: none; background-color: inherit;">=</span><span class="attribute-value" style="margin: 0px; padding: 0px; border: none; background-color: inherit;">"wrap_content"</span><span style="margin: 0px; padding: 0px; border: none; background-color: inherit;">  </span></span></li><li class="alt" style="border-style: none none none solid; border-left-width: 3px; border-left-color: rgb(153, 153, 153); list-style: decimal-leading-zero outside; color: inherit; line-height: 18px; margin: 0px !important; padding: 0px 3px 0px 10px !important;"><span style="margin: 0px; padding: 0px; border: none; color: black; background-color: inherit;"><span class="attribute" style="margin: 0px; padding: 0px; border: none; color: red; background-color: inherit;">android:headerDividersEnabled</span><span style="margin: 0px; padding: 0px; border: none; background-color: inherit;">=</span><span class="attribute-value" style="margin: 0px; padding: 0px; border: none; background-color: inherit;">"false"</span><span style="margin: 0px; padding: 0px; border: none; background-color: inherit;">  </span></span></li><li style="margin: 0px !important; padding: 0px 3px 0px 10px !important; border-style: none none none solid; border-left-width: 3px; border-left-color: rgb(153, 153, 153); list-style: decimal-leading-zero outside; color: rgb(119, 119, 119); line-height: 18px; background-color: rgb(249, 249, 249);"><span style="margin: 0px; padding: 0px; border: none; color: black; background-color: inherit;"><span class="attribute" style="margin: 0px; padding: 0px; border: none; color: red; background-color: inherit;">android:footerDividersEnabled</span><span style="margin: 0px; padding: 0px; border: none; background-color: inherit;">=</span><span class="attribute-value" style="margin: 0px; padding: 0px; border: none; background-color: inherit;">"false"</span><span style="margin: 0px; padding: 0px; border: none; background-color: inherit;">  </span></span></li><li class="alt" style="border-style: none none none solid; border-left-width: 3px; border-left-color: rgb(153, 153, 153); list-style: decimal-leading-zero outside; color: inherit; line-height: 18px; margin: 0px !important; padding: 0px 3px 0px 10px !important;"><span style="margin: 0px; padding: 0px; border: none; color: black; background-color: inherit;"><span class="attribute" style="margin: 0px; padding: 0px; border: none; color: red; background-color: inherit;">android:divider</span><span style="margin: 0px; padding: 0px; border: none; background-color: inherit;">=</span><span class="attribute-value" style="margin: 0px; padding: 0px; border: none; background-color: inherit;">"@null"</span><span style="margin: 0px; padding: 0px; border: none; background-color: inherit;">  </span></span></li><li style="margin: 0px !important; padding: 0px 3px 0px 10px !important; border-style: none none none solid; border-left-width: 3px; border-left-color: rgb(153, 153, 153); list-style: decimal-leading-zero outside; color: rgb(119, 119, 119); line-height: 18px; background-color: rgb(249, 249, 249);"><span style="margin: 0px; padding: 0px; border: none; color: black; background-color: inherit;"><span class="tag" style="margin: 0px; padding: 0px; border: none; color: green; font-weight: bold; background-color: inherit;">/></span><span style="margin: 0px; padding: 0px; border: none; background-color: inherit;">  </span></span></li></ol></div>
<div class="line"><span class="text plain"><span class="meta paragraph text"></span></span></div>

5.改写SampleActivity.java类中getListView()方法:

<div class="line"><span class="text plain"><span class="meta paragraph text"></span></span></div><div class="dp-highlighter bg_java" style="font-family: Consolas, 'Courier New', Courier, mono, serif; font-size: 12px; width: 938.516px; overflow: hidden; padding-top: 1px; border-color: rgb(204, 204, 204); background-color: rgb(231, 229, 220); margin: 18px 0px !important;"><div class="bar" style="padding-left: 45px;"><div class="tools" style="padding: 3px 8px 10px 10px; font-size: 9px; line-height: normal; font-family: Verdana, Geneva, Arial, Helvetica, sans-serif; color: silver; border-left-width: 3px; border-left-style: solid; border-left-color: rgb(153, 153, 153); background-color: rgb(248, 248, 248);"><strong>[java]</strong> <a target=_blank href="http://blog.csdn.net/tongcpp/article/details/40372521#" class="ViewSource" title="view plain" style="text-decoration: none; border: none; padding: 0px; margin: 0px 10px 0px 0px; color: rgb(12, 137, 207); background-image: none; background-color: inherit; background-position: initial initial; background-repeat: initial initial;">view plain</a><a target=_blank href="http://blog.csdn.net/tongcpp/article/details/40372521#" class="CopyToClipboard" title="copy" style="text-decoration: none; border: none; padding: 0px; margin: 0px 10px 0px 0px; color: rgb(12, 137, 207); background-image: none; background-color: inherit; background-position: initial initial; background-repeat: initial initial;">copy</a><a target=_blank href="http://blog.csdn.net/tongcpp/article/details/40372521#" class="PrintSource" title="print" style="text-decoration: none; border: none; padding: 0px; margin: 0px 10px 0px 0px; color: rgb(12, 137, 207); background-image: none; background-color: inherit; background-position: initial initial; background-repeat: initial initial;">print</a><a target=_blank href="http://blog.csdn.net/tongcpp/article/details/40372521#" class="About" title="?" style="text-decoration: none; border: none; padding: 0px; margin: 0px 10px 0px 0px; color: rgb(12, 137, 207); background-image: none; background-color: inherit; background-position: initial initial; background-repeat: initial initial;">?</a><a target=_blank href="https://code.csdn.net/snippets/492335" target="_blank" title="在CODE上查看代码片" style="text-decoration: none; border: none; padding: 0px; margin: 0px 10px 0px 0px; color: rgb(12, 137, 207); background-image: none; background-color: inherit; background-position: initial initial; background-repeat: initial initial;"><img src="https://code.csdn.net/assets/CODE_ico.png" width="12" height="12" alt="在CODE上查看代码片" style="border: none; position: relative; top: 1px; left: 2px;" /></a><a target=_blank href="https://code.csdn.net/snippets/492335/fork" target="_blank" title="派生到我的代码片" style="text-decoration: none; border: none; padding: 0px; margin: 0px 10px 0px 0px; color: rgb(12, 137, 207); background-image: none; background-color: inherit; background-position: initial initial; background-repeat: initial initial;"><img src="https://code.csdn.net/assets/ico_fork.svg" width="12" height="12" alt="派生到我的代码片" style="border: none; position: relative; top: 2px; left: 2px;" /></a><div style="position: absolute; left: 558px; top: 2082px; width: 29px; height: 15px; z-index: 99;"><embed id="ZeroClipboardMovie_4" src="http://static.blog.csdn.net/scripts/ZeroClipboard/ZeroClipboard.swf" loop="false" menu="false" quality="best" bgcolor="#ffffff" width="29" height="15" name="ZeroClipboardMovie_4" align="middle" allowscriptaccess="always" allowfullscreen="false" type="application/x-shockwave-flash" pluginspage="http://www.macromedia.com/go/getflashplayer" flashvars="id=4&width=29&height=15" wmode="transparent" style="animation-duration: 0.001s; animation-name: playerInserted;" /></div></div></div><ol start="1" class="dp-j" style="padding: 0px; border: none; list-style-position: initial; list-style-image: initial; color: rgb(92, 92, 92); background-color: rgb(255, 255, 255); margin: 0px 0px 1px 45px !important;"><li class="alt" style="border-style: none none none solid; border-left-width: 3px; border-left-color: rgb(153, 153, 153); list-style: decimal-leading-zero outside; color: inherit; line-height: 18px; margin: 0px !important; padding: 0px 3px 0px 10px !important;"><span style="margin: 0px; padding: 0px; border: none; color: black; background-color: inherit;"><span style="margin: 0px; padding: 0px; border: none; background-color: inherit;">mpPullToRefreshPinnedSectionListView = (PullToRefreshPinnedSectionListView) findViewById(R.id.list);  </span></span></li><li style="margin: 0px !important; padding: 0px 3px 0px 10px !important; border-style: none none none solid; border-left-width: 3px; border-left-color: rgb(153, 153, 153); list-style: decimal-leading-zero outside; color: rgb(119, 119, 119); line-height: 18px; background-color: rgb(249, 249, 249);"><span style="margin: 0px; padding: 0px; border: none; color: black; background-color: inherit;"><span class="keyword" style="margin: 0px; padding: 0px; border: none; color: green; font-weight: bold; background-color: inherit;">return</span><span style="margin: 0px; padding: 0px; border: none; background-color: inherit;"> mpPullToRefreshPinnedSectionListView.getRefreshableView();  </span></span></li></ol></div>
<div class="line"><span class="text plain"><span class="meta paragraph text"></span></span></div>

即可通过

<div class="line"><span class="text plain"><span class="meta paragraph text"></span></span></div>
[java]  view plain copy print ? 在CODE上查看代码片 派生到我的代码片
  1. ListView list = getListView();  

继续进行原example其他操作,详情可阅读项目代码

另一种实现方式

本例的实现方式依赖于handmark版下拉刷新组件的灵活性,更重要的一点,要求分段头悬停组件是继承自ListView实现;故同理也可用handmark版下拉刷新组件和1.x版的StickyListHeaders组件实现;

另一种实现方式为pull-to-refresh-sticky-list,其采取合并的是2.x版的StickyListHeaders和johannilsson的android-pulltorefresh,实现形式不同,但效果类似,看过代码后实现起来也“相当顺畅”,有兴趣的同学可以参照此项目;

建议

建议在熟悉或使用过原有组件类库的前提下使用本类库。

良心的公众号,更多精品文章,不要忘记关注哈

《Android和Java技术栈》


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值