基于XListView的基础上,把它的头部刷新换成自己定义的控件,这与IOS版上的QQ刷新类似。效果如下:
水滴效果可以看我的上一篇博客
水滴效果实现
由于这是基于XListView 的,所以大部分代码就不贴了,只是把头部的headerview代码修改。
xlistview_waterEffect.getLayoutParams().height = height;
xlistview_waterEffect.requestLayout();
public void setVisiableHeight(int height) {
if (height < 0) {
height = 0;
}
LinearLayout.LayoutParams lp = (LinearLayout.LayoutParams) mContainer
.getLayoutParams();
lp.height = height;
mContainer.setLayoutParams(lp);
if (height > dip2px(getContext(), 120)) {
height = dip2px(getContext(), 120);
}
xlistview_header_content.getLayoutParams().height = height;
xlistview_header_content.requestLayout();
xlistview_waterEffect.getLayoutParams().height = height;
xlistview_waterEffect.requestLayout();
}
<xlistview.XListView
android:id="@+id/xlistview"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:cacheColorHint="#ffffff"/>
private void initData(){
testData = new ArrayList();
refreshData();
xlistview.setPullLoadEnable(true);
arrayAdapter = new ArrayAdapter<>(this, android.R.layout.simple_list_item_1, testData);
xlistview.setAdapter(arrayAdapter);
xlistview.setXListViewListener(new IXListViewListener() {
@Override
public void onRefresh() {
handler.sendEmptyMessageDelayed(0, 1000);
}
@Override
public void onLoadMore() {
handler.sendEmptyMessageDelayed(1, 1000);
}
});
}
Handler handler = new Handler(){
public void dispatchMessage(android.os.Message msg) {
switch(msg.what){
case 0:
refreshData();
arrayAdapter.notifyDataSetChanged();
break;
case 1:
loadData();
break;
}
stopXlistView();
};
};
private void refreshData(){
testData.clear();
for(int i=0;i<10;i++){
testData.add("测试=="+i);
}
}
private void loadData(){
for(int i=0;i<10;i++){
testData.add("load===="+i);
}
arrayAdapter.notifyDataSetChanged();
}
private void stopXlistView(){
xlistview.stopRefresh();
xlistview.stopLoadMore();
}
height > dip2px(getContext(), 120),其中在这里设置它的高度为120dp.
public void setVisiableHeight(int height) {
if (height < 0) {
height = 0;
}
LinearLayout.LayoutParams lp = (LinearLayout.LayoutParams) mContainer
.getLayoutParams();
lp.height = height;
mContainer.setLayoutParams(lp);
if (height > dip2px(getContext(), 120)) {
height = dip2px(getContext(), 120);
}
xlistview_header_content.getLayoutParams().height = height;
xlistview_header_content.requestLayout();
xlistview_waterEffect.getLayoutParams().height = height;
xlistview_waterEffect.requestLayout();
}
直接在WaterEffect.java中修改
private float bigRadius = 18;// 大圆半径
private float smallRadius = 12;// 小圆半径
分别在xlistview_header.xml、xlistview_footer.xml,中把ProgressBar控件替换即可。
关键是水滴效果的实现,这个刷新效果我是基于XListView 来修改的,水滴效果可以参考我上一篇博客。这和QQ的不是完全一样的。
具体代码也上传了。
源码