asynclayoutinflater特點
用法
//初始化
asynclayoutinflater masynclayoutinflater = new asynclayoutinflater(context);
......
//呼叫
masynclayoutinflater.inflate(layoutid, parent, new asynclayoutinflater.oninflatefinishedlistener()
});
業務方通過設定asynclayoutinflater.oninflatefinishedlistener監聽,獲取非同步inflate的結果。
關鍵屬性和方法
layoutinflater minflater;
handler mhandler;
inflatethread minflatethread;
handler mhandler
inflatethread minflatethread
public void inflate(@layoutres int resid, @nullable viewgroup parent,
@nonnull oninflatefinishedlistener callback)
@uithread
public void inflate(@layoutres int resid, @nullable viewgroup parent,
@nonnull oninflatefinishedlistener callback)
inflaterequest request = minflatethread.obtainrequest();
request.inflater = this;
request.resid = resid;
request.parent = parent;
request.callback = callback;
minflatethread.enqueue(request);
}
將新的resid的非同步inflate操作封裝到inflaterequest物件中,並通過enqueue@inflatethread方法加入到非同步執行緒的任務佇列中,
public void enqueue(inflaterequest request) catch (interruptedexception e)
}
關鍵類—inflatethread
inflatethread 繼承於thread,是個單例項執行緒類,其關鍵成員fields如下
private arrayblockingqueuemqueue = new arrayblockingqueue<>(10);
private synchronizedpoolmrequestpool = new synchronizedpool<>(10);
inflatethread在其static**塊中完成初始化和啟動
static
private callback mhandlercallback = new callback()
request.callback.oninflatefinished(
request.view, request.resid, request.parent);
minflatethread.releaserequest(request);
return true;
}};
相關方法
//復用inflaterequest
public inflaterequest obtainrequest()
return obj;
}//**inflaterequest
public void releaserequest(inflaterequest obj)
obtainrequest從mrequestpool中獲取inflaterequest物件,不成功就新建;
releaserequest將已經inflate過的inflaterequest加入復用物件池。
關鍵類—basicinflater
private
static
class
basicinflater
extends
layoutinflater;.
....
.@override
protected view oncreateview
(string name, attributeset attrs)
throws classnotfoundexception
}catch
(classnotfoundexception e)
}return
super
.oncreateview
(name, attrs);}
}
synchronizedpool(androidx.core.util.pools.synchronizedpool)
Cartographer原始碼篇 原始碼分析 1
在安裝編譯cartographer 1.0.0的時候,我們可以看到 主要包括cartorgarpher ros cartographer ceres sover三個部分。其中,ceres solver用於非線性優化,求解最小二乘問題 cartographer ros為ros平台的封裝,獲取感測器資料...
AbstractListView原始碼分析3
normal list that does not indicate choices public static final int choice mode none 0 the list allows up to one choice public static final int choice ...
Android AsyncTask原始碼分析
android中只能在主線程中進行ui操作,如果是其它子執行緒,需要借助非同步訊息處理機制handler。除此之外,還有個非常方便的asynctask類,這個類內部封裝了handler和執行緒池。本文先簡要介紹asynctask的用法,然後分析具體實現。asynctask是乙個抽象類,我們需要建立子...