自定義下拉重新整理的listview

2021-07-10 18:37:09 字數 1733 閱讀 5941

listview的下拉重新整理功能的實現依靠在listview前面加上頭布局,通過判斷頭布局的位置確實使用者是否下拉,然後根據情況進行處理

public class reflashlistview extends listview implements onscrolllistener 

public reflashlistview(context context, attributeset attrs)

public reflashlistview(context context)

private void initviews()

/*** 設定mheardview布局的上邊距

* * @param i

*/private void toppadding(int i)

/*** 通知父布局headerview的尺寸(便於後面測量headerview的高度)

* * @param child

*/private void measureview(view child)

// 1.左右邊距 2.內邊距 3.子布局寬度

int childwidthspec = viewgroup.getchildmeasurespec(0, 0, params.width);

int lpheight = params.height;

int childheightspec;

if (lpheight > 0) else

child.measure(childwidthspec, childheightspec);

}@override

public void onscrollstatechanged(abslistview view, int scrollstate)

@override

public void onscroll(abslistview view, int firstvisibleitem,

int visibleitemcount, int totalitemcount) else

}@override

public boolean ontouchevent(motionevent ev)

if (state == refreshing)

int tempy = (int) ev.gety();

int dy = tempy - starty; // 偏移量

log.d("tag", "偏移量:" + dy);

if (dy > 0) else if (pading < 0 && state != pull_to_refresh)

return true;

}break;

case motionevent.action_up:

starty = -1;// 重置

if (state == release_refresh) else if (state == pull_to_refresh)

break;

default:

break;

}return super.ontouchevent(ev);

}/**

* 通過state值改變hearerview狀態

*/private void refreshstate()

}/**

* 初始化箭頭動畫

*/private void initarrowanim()

}

自定義下拉重新整理控制項

一 前言 二 了解 uirefreshcontrol 初始化乙個control uirefreshcontrol control uirefreshcontrol alloc init 給control 新增乙個重新整理方法 control addtarget self action selecto...

scroll view實現自定義下拉重新整理

refresher enabled true 開啟下拉重新整理 refresher triggered 設定當前下拉重新整理狀態,true 表示下拉重新整理已經被觸發,false 表示下拉重新整理未被觸發 bindrefresherrefresh 自定義下拉重新整理被觸發事件 bindscrollt...

iOS 自定義MJRefresh下拉重新整理動畫

實現如下 mjrefreshgifheader繼承自mj中的mjrefreshgifheader import mjrefreshgifheader.h inte ce customrefreshgifheader mjrefreshgifheader 設定state狀態下的動畫images 動畫持...