锤子下拉
“锤子下拉”,东半球最优雅的下拉控件。(也叫SmartisanRefreshableLayout。)
涉及到的知识点包括:自定义View、自定义ViewGroup、事件分发、属性动画等。
说明
本项目模仿“锤子阅读”的下拉效果。仅供学习交流,请勿用于商业用途。
Because the animation in my project imitates the one in Smartisan OS. Only communicate using, please do not used for commercial purposes or illegal purposes, thank you!
介绍
下面是我做的过程中,每个阶段有意思的地方: (下面把“可刷新”的最小距离叫刷新距离)
使用
首先,在布局文件中使用SmartisanRefreshableLayout
只需在里面加入ListView,仍然保持了ListView的正常使用,不会对它造成什么影响。
<com.hougr.smartisanpull.SmartisanRefreshableLayout
android:id="@+id/refreshable_view"
android:layout_width="fill_parent"
android:layout_height="fill_parent" >
<ListView
android:id="@+id/list_view"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="#ffffff"
android:scrollbars="none" >
</ListView>
</com.hougr.smartisanpull.SmartisanRefreshableLayout>
然后,实现下拉事件的监听
mSmartisanRefreshableLayout = (SmartisanRefreshableLayout) findViewById(R.id.refreshable_view);
mSmartisanRefreshableLayout.setOnRefreshListener(new SmartisanRefreshableLayout.PullToRefreshListener() {
@Override
public void onRefresh() {
try {
Thread.sleep(1500);
} catch (InterruptedException e) {
e.printStackTrace();
}
}
@Override
public void onRefreshFinished() {
mSmartisanRefreshableLayout.finishRefreshing();
mViewHolderAdapter.addToListHead((mRefreshCount++)+" 喜欢的话,可以在github上赏我一颗star");
}
});
接下来
接下来,会增加对RecyclerView的支持。
拜托
喜欢的话,可以点击右上角的star。感谢。
License 代码版权
The MIT License (MIT)
Copyright (c) 2016 hougr
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.