notifyItemChanged(int position) 更新列表position位置上的數(shù)據(jù)可以調(diào)用
notifyItemInserted(int position) 列表position位置添加一條數(shù)據(jù)時(shí)可以調(diào)用,伴有動(dòng)畫(huà)效果
notifyItemRemoved(int position) 列表position位置移除一條數(shù)據(jù)時(shí)調(diào)用,伴有動(dòng)畫(huà)效果
notifyItemMoved(int fromPosition, int toPosition) 列表fromPosition位置的數(shù)據(jù)移到toPosition位置時(shí)調(diào)用,伴有動(dòng)畫(huà)效果
notifyItemRangeChanged(int positionStart, int itemCount) 列表從positionStart位置到itemCount數(shù)量的列表項(xiàng)進(jìn)行數(shù)據(jù)刷新
notifyItemRangeInserted(int positionStart, int itemCount) 列表從positionStart位置到itemCount數(shù)量的列表項(xiàng)批量添加數(shù)據(jù)時(shí)調(diào)用,伴有動(dòng)畫(huà)效果
notifyItemRangeRemoved(int positionStart, int itemCount) 列表從positionStart位置到itemCount數(shù)量的列表項(xiàng)批量刪除數(shù)據(jù)時(shí)調(diào)用,伴有動(dòng)畫(huà)效果
簡(jiǎn)介:
提供一個(gè)讓有限的窗口變成一個(gè)大數(shù)據(jù)集的靈活視圖。
術(shù)語(yǔ)表:
Adapter:RecyclerView的子類(lèi)。負(fù)責(zé)提供在一個(gè)數(shù)據(jù)集中子item顯示布局的適配器。Position:在一個(gè)適配器子item的位置。Index:用于調(diào)用getChildAt(int)時(shí)根據(jù)位置進(jìn)行添加子視圖的下標(biāo)。Binding:在適配器中的位置顯示數(shù)據(jù)的過(guò)程Recycle (view):以前用于將特定的適配器位置顯示數(shù)據(jù)的視圖可以放置在稍后再使用的緩存中,隨后再次顯示相同類(lèi)型的數(shù)據(jù)。這可以大大提高性能,跳過(guò)初始布局膨脹或創(chuàng)建。Scrap (view):在布局中已進(jìn)入一個(gè)臨時(shí)分離狀態(tài)的小視圖。不用的界面可以重復(fù)使用不必完全從父recyclerview分離,如果覺(jué)得view是dirty,直接修改假如不需要重新綁定的,或者修改適配器。Dirty (view): 在顯示之前,必須在適配器上彈回的子視圖。
概要
XML 屬性
layoutManager 用法跟 Layout Manager類(lèi)一樣
Public Methods
public void addFocusables (ArrayList views, int direction, int focusableMode)
將需要獲得焦點(diǎn)的View添加到獲得焦點(diǎn)視圖的列表中。
Parameters views 不為空的view集合 direction 焦點(diǎn)的方向。 focusableMode 要添加的focusables類(lèi)型。
public void addItemDecoration (RecyclerView.ItemDecoration decor)
在recyclerview添加一個(gè)recyclerview.itemdecoration。 Item decorations可以影響測(cè)量和繪制單個(gè)子視圖。
Item decorations 是一個(gè)指令. 放置在列表前面的裝飾物將被運(yùn)行/queried/繪制首先對(duì)項(xiàng)目視圖的影響。添加到視圖的Padding將被嵌套;早期的裝飾添加的填充物將意味著該列表中的進(jìn)一步項(xiàng)目裝飾將被要求在前一個(gè)裝飾區(qū)內(nèi)draw/pad 。
Parameters decor 添加的裝飾
public void addItemDecoration (RecyclerView.ItemDecoration decor, int index)
用法同上
Parameters decor Decoration to add index 在裝飾鏈中插入這一裝飾的位置。如果這個(gè)值是負(fù)的裝飾將增加在最后。
public void addOnChildAttachStateChangeListener (RecyclerView.OnChildAttachStateChangeListener listener)
注冊(cè)一個(gè)監(jiān)聽(tīng)器,將通知每當(dāng)子視圖連接或脫離recyclerview。
該監(jiān)聽(tīng)器是調(diào)用LayoutManager或recyclerview判斷子視圖不再需要。如果一個(gè)應(yīng)用程序?qū)嘿F的或重量級(jí)的數(shù)據(jù)與項(xiàng)目視圖關(guān)聯(lián),這可能是釋放或釋放這些資源的好地方。
Parameters listener Listener to register
public void addOnItemTouchListener (RecyclerView.OnItemTouchListener listener)
添加一個(gè)recyclerview.onitemtouchlistener攔截觸摸事件之前他們被派遣到子視圖或視圖的標(biāo)準(zhǔn)滾動(dòng)行為。
客戶(hù)端代碼可以使用監(jiān)聽(tīng)器來(lái)實(shí)現(xiàn)項(xiàng)目操作行為。一旦一個(gè)監(jiān)聽(tīng)器返回從onintercepttouchevent(recyclerview,位移事件)的onTouchEvent(recyclerview,位移事件)的方法將為每個(gè)輸入位移事件直到姿態(tài)結(jié)束。
Parameters listener Listener to add 也可以看 RecyclerView.SimpleOnItemTouchListener
public void addOnScrollListener (RecyclerView.OnScrollListener listener)
添加一個(gè)監(jiān)聽(tīng)器,將通知任何更改滾動(dòng)狀態(tài)或位置。
添加一個(gè)監(jiān)聽(tīng)器的組件應(yīng)該小心地把它刪除完畢。,獲取擁有者的其他的組件可以調(diào)用clearonscrolllisteners()去除所有附加的監(jiān)聽(tīng)者。
Parameters listener listener to set or null to clear
public void clearOnChildAttachStateChangeListeners ()
移除所有通addonchildattachstatechangelistener(onchildattachstatechangelistener)添加的監(jiān)聽(tīng)者。
public void clearOnScrollListeners ()
刪除所有的其余監(jiān)聽(tīng)器,通知任何更改滾動(dòng)狀態(tài)或位置。
public int computeHorizontalScrollExtent ()
計(jì)算水平滾動(dòng)條上的滑塊在水平范圍內(nèi)的橫向距離。這個(gè)值是用來(lái)計(jì)算拇指長(zhǎng)度內(nèi)滾動(dòng)的軌跡。
范圍表示在任意的單位,必須按照computehorizontalscrollrange()和computehorizontalscrolloffset()單位使用相同的。
默認(rèn)實(shí)現(xiàn)返回0。
如果你想支持滾動(dòng)條,在你的LayoutManager覆蓋computehorizontalscrollextent(recyclerview.state)。
Returns The horizontal extent of the scrollbar’s thumb See Also computeHorizontalScrollExtent(RecyclerView.State)
public int computeHorizontalScrollOffset ()
計(jì)算水平滾動(dòng)條上的滑塊在水平范圍內(nèi)的橫向偏移。這個(gè)值是用來(lái)計(jì)算拇指長(zhǎng)度內(nèi)滾動(dòng)的軌跡。
范圍表示在任意的單位,必須按照computehorizontalscrollrange()和computehorizontalscrollextent()單位使用相同的。
默認(rèn)實(shí)現(xiàn)返回0。
如果你想支持滾動(dòng)條,在你的LayoutManager覆蓋computehorizontalscrollextent(recyclerview.state)。
Returns The horizontal offset of the scrollbar’s thumb See Also (RecyclerView.Adapter)
public int computeHorizontalScrollRange ()
計(jì)算出水平滾動(dòng)條的水平距離。
范圍表示在任意的單位,必須按照computehorizontalscrollextent()和computehorizontalscrolloffset()單位使用相同的。
默認(rèn)實(shí)現(xiàn)返回0。
如果你想支持滾動(dòng)條,在你的LayoutManager覆蓋computehorizontalscrollextent(recyclerview.state)。
Returns The total horizontal range represented by the vertical scrollbar
See Also computeHorizontalScrollRange(RecyclerView.State)
public int computeVerticalScrollExtent ()
計(jì)算的垂直滾動(dòng)條上的滑塊在垂直范圍內(nèi)的垂直距離。這個(gè)值是用來(lái)計(jì)算拇指長(zhǎng)度內(nèi)滾動(dòng)的軌跡。
范圍表示在任意的單位,必須按照computeverticalscrollrange()和computeverticalscrolloffset()單位使用相同的。
默認(rèn)實(shí)現(xiàn)返回0。
如果你想支持滾動(dòng)條,在你的LayoutManager覆蓋computehorizontalscrollextent(recyclerview.state)。
Returns The vertical extent of the scrollbar’s thumb See Also computeVerticalScrollExtent(RecyclerView.State)
public int computeVerticalScrollOffset ()
計(jì)算的垂直滾動(dòng)條上在垂直范圍內(nèi)的滑塊垂直偏移。這個(gè)值是用來(lái)計(jì)算拇指長(zhǎng)度內(nèi)滾動(dòng)的軌跡。
范圍表示在任意的單位,必須按照computeverticalscrollrange()和computeverticalscrolloffset()單位使用相同的。
默認(rèn)實(shí)現(xiàn)返回0。
如果你想支持滾動(dòng)條,在你的LayoutManager覆蓋computehorizontalscrollextent(recyclerview.state)。
Returns The vertical offset of the scrollbar’s thumb See Also (RecyclerView.Adapter)
public int computeVerticalScrollRange ()
計(jì)算的垂直距離,垂直滾動(dòng)條代表。
范圍表示在任意的單位,必須按照computeverticalscrollrange()和computeverticalscrolloffset()單位使用相同的。
默認(rèn)實(shí)現(xiàn)返回0。
如果你想支持滾動(dòng)條,在你的LayoutManager覆蓋computehorizontalscrollextent(recyclerview.state)。
Returns The total vertical range represented by the vertical scrollbar
See Also computeVerticalScrollRange(RecyclerView.State)
public boolean dispatchNestedFling (float velocityX, float velocityY, boolean consumed)
向一個(gè)嵌套滾動(dòng)父控件發(fā)送一次一次的發(fā)送。
此方法應(yīng)該被用來(lái)表示一個(gè)嵌套滾動(dòng)的子視圖已經(jīng)檢測(cè)到一個(gè)一個(gè)的合適的條件。通常這意味著觸摸滾動(dòng)結(jié)束在滾動(dòng),滿(mǎn)足或超過(guò)最小投擲速度沿滾動(dòng)軸方向的速度。
如果一個(gè)嵌套的滾動(dòng)視圖通常會(huì)拋出,但它是在它自己的內(nèi)容的邊緣,它可以使用此方法將其委托給它的嵌套滾動(dòng)的父控件。父控件可以隨意地使用一次或觀察一個(gè)子視圖扔。
Parameters velocityX Horizontal fling velocity in pixels per second velocityY Vertical fling velocity in pixels per second consumed true if the child consumed the fling, false otherwise Returns true if the nested scrolling parent consumed or otherwise reacted to the fling
public boolean dispatchNestedPreFling (float velocityX, float velocityY)
在這個(gè)視圖處理之前,將一個(gè)發(fā)送給嵌套滾動(dòng)的父控件。
嵌套的預(yù)拋事件是接觸和嵌套的預(yù)滾動(dòng)是嵌套的事件。dispatchnestedprefling偏移條件,在子視圖消耗它之前父視圖完全消耗嵌套滑動(dòng)。如果該方法返回true,則嵌套的父視圖將被消耗掉,而該視圖不應(yīng)該滾動(dòng)。
對(duì)于一個(gè)更好的用戶(hù)體驗(yàn),只有一個(gè)視圖中的嵌套滾動(dòng)鏈應(yīng)該依次被消耗。如果一個(gè)父視圖消耗了這個(gè)方法,該方法將返回false。自定義視圖的實(shí)現(xiàn)應(yīng)該以2種方式來(lái)解釋?zhuān)?br>
如果一個(gè)自定義視圖分頁(yè)需要解決的一個(gè)固定的頁(yè)面上,不叫dispatchnestedprefling;消費(fèi)將解決一個(gè)有效的位置無(wú)關(guān)。 如果一個(gè)嵌套的父控件會(huì)消耗掉這一點(diǎn),這個(gè)視圖就不應(yīng)該滾動(dòng),甚至可以解決一個(gè)有效的空閑位置。 視圖應(yīng)該也不提供拋速度嵌套父視圖沿軸滾動(dòng)目前不支持;ScrollView不應(yīng)該提供水平掃視速度其父母從滾動(dòng)沿著軸是不允許攜帶速度沿運(yùn)動(dòng)是沒(méi)有道理的。
Parameters velocityX Horizontal fling velocity in pixels per second velocityY Vertical fling velocity in pixels per second Returns true if a nested scrolling parent consumed the fling
public boolean dispatchNestedPreScroll (int dx, int dy, int[] consumed, int[] offsetInWindow)
在這個(gè)視圖消耗任何部分的情況之前,在進(jìn)行中的嵌套滾動(dòng)調(diào)度的一個(gè)步驟。
嵌套預(yù)滾動(dòng)事件是攔截觸摸嵌套滾動(dòng)事件。dispatchnestedprescroll提供了一個(gè)機(jī)會(huì),在子視圖消耗它之前,嵌套的滾動(dòng)操作的父視圖消耗一些或所有的滾動(dòng)操作。
Parameters dx Horizontal scroll distance in pixels dy Vertical scroll distance in pixels consumed Output. If not null, consumed[0] will contain the consumed component of dx and consumed[1] the consumed dy. offsetInWindow Optional. If not null, on return this will contain the offset in local view coordinates of this view from before this operation to after it completes. View implementations may use this to adjust expected input coordinate tracking. Returns true if the parent consumed some or all of the scroll delta
public boolean dispatchNestedScroll (int dxConsumed, int dyConsumed, int dxUnconsumed, int dyUnconsumed, int[] offsetInWindow)
一步一個(gè)嵌套滾動(dòng)的進(jìn)度。
支持嵌套滾動(dòng)的視圖的實(shí)現(xiàn),應(yīng)該將此調(diào)用此報(bào)告信息,以向當(dāng)前嵌套滾動(dòng)的父控件。如果一個(gè)嵌套滾動(dòng)不是當(dāng)前正在進(jìn)行中的或嵌套滾動(dòng),則此方法沒(méi)有啟用此方法。
兼容視圖實(shí)現(xiàn)應(yīng)該也在消耗自己的滾動(dòng)事件組件調(diào)用dispatchnestedprescroll。
Parameters dxConsumed Horizontal distance in pixels consumed by this view during this scroll step dyConsumed Vertical distance in pixels consumed by this view during this scroll step dxUnconsumed Horizontal scroll distance in pixels not consumed by this view dyUnconsumed Horizontal scroll distance in pixels not consumed by this view offsetInWindow Optional. If not null, on return this will contain the offset in local view coordinates of this view from before this operation to after it completes. View implementations may use this to adjust expected input coordinate tracking. Returns true if the event was dispatched, false if it could not be dispatched.
public void draw (Canvas c)
繪制view的方法
Parameters c The Canvas to which the View is rendered.
public boolean drawChild (Canvas canvas, View child, long drawingTime)
在View Group 繪制一個(gè)子view。這種方法是負(fù)責(zé)在正確的狀態(tài)得到畫(huà)布。這包括裁剪,將使子view的滾動(dòng)的起源是在0,0,和使用任何動(dòng)畫(huà)轉(zhuǎn)換。
Parameters canvas The canvas on which to draw the child child Who to draw drawingTime The time at which draw is occurring Returns True if an invalidate() was issued
public View findChildViewUnder (float x, float y)
給定的點(diǎn)下找到的最頂層視圖。
Parameters x Horizontal position in pixels to search y Vertical position in pixels to search Returns The child view under (x, y) or null if no matching child is found
public RecyclerView.ViewHolder findViewHolderForAdapterPosition (int position)
返回的數(shù)據(jù)集的特定位置的項(xiàng)目viewholder。不像findviewholderforlayoutposition(int)這種方法考慮到任何掛起的適配器的變化可能不會(huì)反映到尚未布局。另一方面,如果notifydatasetchanged()被稱(chēng)為但新布局尚未計(jì)算,此方法將返回空直到從未知的布局計(jì)算views的新位置。 這種方法檢查只有recyclerview的子view。如果該項(xiàng)目在給定的位置沒(méi)有被安排,它不會(huì)創(chuàng)建一個(gè)新的。
Parameters position The position of the item in the data set of the adapter Returns The ViewHolder at position or null if there is no such item
public RecyclerView.ViewHolder findViewHolderForItemId (long id)
返回與給定的ID。recyclerview必須使用stableids適配器返回一個(gè)非空值的項(xiàng)的viewholder。
這種方法檢查只有recyclerview的子view。如果該項(xiàng)目在給定的位置沒(méi)有被安排,它不會(huì)創(chuàng)建一個(gè)新的。
Parameters id The id for the requested item Returns The ViewHolder with the given id or null if there is no such item
public RecyclerView.ViewHolder findViewHolderForLayoutPosition (int position)
返回在設(shè)定的新布局,通過(guò)數(shù)據(jù)的給定位置的項(xiàng)目viewholder。
這種方法檢查只有recyclerview的子view。如果該項(xiàng)目在給定的位置沒(méi)有被安排,它不會(huì)創(chuàng)建一個(gè)新的。
注意,當(dāng)適配器的內(nèi)容改變,viewholder位置直到下一步布局計(jì)算更新。如果有掛起的適配器更新,該方法的返回值可能無(wú)法匹配您的適配器內(nèi)容。你可以使用# getadapterposition()得到一個(gè)viewholder當(dāng)前適配器的位置。
Parameters position The position of the item in the data set of the adapter Returns The ViewHolder at position or null if there is no such item
public RecyclerView.ViewHolder findViewHolderForPosition (int position)
This method is deprecated. use findViewHolderForLayoutPosition(int) or findViewHolderForAdapterPosition(int)
public boolean fling (int velocityX, int velocityY)
Begin a standard fling with an initial velocity along each axis in pixels per second. If the velocity given is below the system-defined minimum this method will return false and no fling will occur.
Parameters velocityX Initial horizontal velocity in pixels per second velocityY Initial vertical velocity in pixels per second Returns true if the fling was started, false if the velocity was too low to fling or LayoutManager does not support scrolling in the axis fling is issued. See Also canScrollVertically() canScrollHorizontally()
public View focusSearch (View focused, int direction)
Find the nearest view in the specified direction that wants to take focus.
Parameters focused The view that currently has focus direction One of FOCUS_UP, FOCUS_DOWN, FOCUS_LEFT, and FOCUS_RIGHT, or 0 for not applicable.
public ViewGroup.LayoutParams generateLayoutParams (AttributeSet attrs)
Returns a new set of layout parameters based on the supplied attributes set.
Parameters attrs the attributes to build the layout parameters from Returns an instance of ViewGroup.LayoutParams or one of its descendants
public Adapter getAdapter ()
Retrieves the previously set adapter or null if no adapter is set.
Returns The previously set adapter See Also setAdapter(Adapter)
public int getBaseline ()
返回從其頂部邊界的recyclerview文本基線偏移。如果這recyclerview的布局管理器不支持基線對(duì)齊,此方法返回-1。
Returns the offset of the baseline within the RecyclerView’s bounds or -1 if baseline alignment is not supported
public int getChildAdapterPosition (View child)
Return the adapter position that the given child view corresponds to.
Parameters child Child View to query Returns Adapter position corresponding to the given view or NO_POSITION
public long getChildItemId (View child)
Return the stable item id that the given child view corresponds to.
Parameters child Child View to query Returns Item id corresponding to the given view or NO_ID
public int getChildLayoutPosition (View child)
Return the adapter position of the given child view as of the latest completed layout pass.
This position may not be equal to Item’s adapter position if there are pending changes in the adapter which have not been reflected to the layout yet.
Parameters child Child View to query Returns Adapter position of the given View as of last layout pass or NO_POSITION if the View is representing a removed item.
public RecyclerView.ViewHolder getChildViewHolder (View child)
Retrieve the RecyclerView.ViewHolder for the given child view.
Parameters child Child of this RecyclerView to query for its ViewHolder Returns The child view’s ViewHolder
public RecyclerViewAccessibilityDelegate getCompatAccessibilityDelegate ()
返回可委托實(shí)施的recyclerview使用兼容性。
Returns An instance of AccessibilityDelegateCompat used by RecyclerView
public RecyclerView.ItemAnimator getItemAnimator ()
獲取當(dāng)前itemanimator這recyclerview。一個(gè)空的返回值表示沒(méi)有動(dòng)畫(huà),項(xiàng)目將沒(méi)有任何動(dòng)畫(huà)發(fā)生變化。默認(rèn)情況下,recyclerview實(shí)例化和使用defaultitemanimator實(shí)例。
Returns ItemAnimator The current ItemAnimator. If null, no animations will occur when changes occur to the items in this RecyclerView.
public RecyclerView.LayoutManager getLayoutManager ()
返回當(dāng)前負(fù)責(zé)這recyclerview布局方式的recyclerview.layoutmanager。
Returns The currently bound LayoutManager
public int getMaxFlingVelocity ()
返回的recyclerview用最大滑動(dòng)速度.
Returns The maximum fling velocity used by this RecyclerView.
public int getMinFlingVelocity ()
返回開(kāi)始一次滑動(dòng)的最低速度。
Returns The minimum velocity to start a fling
public RecyclerView.RecycledViewPool getRecycledViewPool ()
檢索此recyclerview的recyclerview.recycledviewpool。這個(gè)方法將永遠(yuǎn)不會(huì)返回空;如果沒(méi)有池是這個(gè)視圖,將創(chuàng)建一個(gè)新的。更多信息見(jiàn)setrecycledviewpool。
Returns The pool used to store recycled item views for reuse. See Also setRecycledViewPool(RecycledViewPool)
public int getScrollState ()
返回的recyclerview當(dāng)前滾動(dòng)狀態(tài)。
Returns SCROLL_STATE_IDLE, SCROLL_STATE_DRAGGING or SCROLL_STATE_SETTLING public boolean hasFixedSize ()
Returns true if the app has specified that changes in adapter content cannot change the size of the RecyclerView itself.
public boolean hasNestedScrollingParent ()
如果這個(gè)視圖有一個(gè)嵌套滾動(dòng)的父控件則返回true。
嵌套滾動(dòng)父控件的存在表明,該視圖已開(kāi)始進(jìn)行嵌套滾動(dòng),并且被一個(gè)父視圖接受進(jìn)一步的視圖層次結(jié)構(gòu)。 Returns whether this view has a nested scrolling parent
public boolean hasPendingAdapterUpdates ()
返回是否有尚未應(yīng)用到布局的尚未掛起的適配器更新。
如果這個(gè)方法返回true,它意味著用戶(hù)當(dāng)前看到的可能不反映他們適配器的內(nèi)容(取決于已更改的內(nèi)容)。您可以使用此信息來(lái)推遲或取消某些操作。
此方法返回true,如果recyclerview尚未計(jì)算第一個(gè)布局后,它是連接到窗口或適配器已被取代。
Returns True if there are some adapter updates which are not yet reflected to layout or false if layout is up to date.
public void invalidateItemDecorations ()
所有itemdecorations無(wú)效。如果recyclerview有物品裝飾,調(diào)用此方法將引發(fā)requestlayout()回調(diào)。
public boolean isAnimating ()
如果recyclerview當(dāng)前正在運(yùn)行的一些動(dòng)畫(huà)返回true。
如果你想被通知當(dāng)動(dòng)畫(huà)完成后,使用時(shí)(itemanimator。itemanimatorfinishedlistener)。
Returns True if there are some item animations currently running or waiting to be started.
public boolean isAttachedToWindow ()
Returns true if RecyclerView is attached to window.
public boolean isNestedScrollingEnabled ()
Returns true if nested scrolling is enabled for this view.
If nested scrolling is enabled and this View class implementation supports it, this view will act as a nested scrolling child view when applicable, forwarding data about the scroll operation in progress to a compatible and cooperating nested scrolling parent.
Returns true if nested scrolling is enabled
public void offsetChildrenHorizontal (int dx)
通過(guò)DX像素偏移的所有子視圖的邊界。用于實(shí)現(xiàn)簡(jiǎn)單的滾動(dòng)layoutmanagers。
Parameters dx Horizontal pixel offset to apply to the bounds of all child views
public void offsetChildrenVertical (int dy)
Offset the bounds of all child views by dy pixels. Useful for implementing simple scrolling in LayoutManagers.
Parameters dy Vertical pixel offset to apply to the bounds of all child views
public void onChildAttachedToWindow (View child)
Called when an item view is attached to this RecyclerView.
Subclasses of RecyclerView may want to perform extra bookkeeping or modifications of child views as they become attached. This will be called before a RecyclerView.LayoutManager measures or lays out the view and is a good time to perform these changes.
Parameters child Child view that is now attached to this RecyclerView and its associated window public void onChildDetachedFromWindow (View child)
Called when an item view is detached from this RecyclerView.
Subclasses of RecyclerView may want to perform extra bookkeeping or modifications of child views as they become detached. This will be called as a RecyclerView.LayoutManager fully detaches the child view from the parent and its window.
Parameters child Child view that is now detached from this RecyclerView and its associated window
public void onDraw (Canvas c)
Implement this to do your drawing.
Parameters c the canvas on which the background will be drawn
public boolean onGenericMotionEvent (MotionEvent event)
實(shí)現(xiàn)這一方法來(lái)處理一般的動(dòng)作事件。 一般的動(dòng)作事件描述的操縱桿移動(dòng),鼠標(biāo),觸控板接觸,滾輪運(yùn)動(dòng)和其他的輸入事件。動(dòng)作事件的源指定接收的輸入的類(lèi)別。此方法的實(shí)現(xiàn)必須在處理事件的源代碼前檢查位。下面的代碼示例演示了如何做。 一般的動(dòng)作事件源類(lèi)source_class_pointer傳遞到指針下的視圖。所有其他通用的運(yùn)動(dòng)事件被傳遞到聚焦視圖。
public boolean onGenericMotionEvent(MotionEvent event) { if (event.isFromSource(InputDevice.SOURCE_CLASS_JOYSTICK)) { if (event.getAction() == MotionEvent.ACTION_MOVE) { // process the joystick movement… return true; } } if (event.isFromSource(InputDevice.SOURCE_CLASS_POINTER)) { switch (event.getAction()) { case MotionEvent.ACTION_HOVER_MOVE: // process the mouse hover movement… return true; case MotionEvent.ACTION_SCROLL: // process the scroll wheel movement… return true; } } return super.onGenericMotionEvent(event); }
Parameters event The generic motion event being processed. Returns True if the event was handled, false otherwise.
public boolean onInterceptTouchEvent (MotionEvent e)
public void onScrollStateChanged (int state)
這recyclerview滾動(dòng)時(shí)的狀態(tài)變化。子類(lèi)應(yīng)該使用此方法來(lái)響應(yīng)狀態(tài)變化,而不是一個(gè)顯式的監(jiān)聽(tīng)器。 這種方法總是在監(jiān)聽(tīng)者之前被調(diào)用,但運(yùn)行在布局管理器響應(yīng)的滾動(dòng)狀態(tài)的變化之后。
Parameters state the new scroll state, one of SCROLL_STATE_IDLE, SCROLL_STATE_DRAGGING or SCROLL_STATE_SETTLING
public void onScrolled (int dx, int dy)
recyclerview改變滾動(dòng)條的位置回調(diào)此方法。子類(lèi)應(yīng)該使用此方法來(lái)響應(yīng)適配器的數(shù)據(jù)集內(nèi)的滾動(dòng),而不是一個(gè)顯式的監(jiān)聽(tīng)器。 這種方法監(jiān)聽(tīng)者之前被調(diào)用。但如果在監(jiān)聽(tīng)者運(yùn)行之后子類(lèi)需要在滾動(dòng)執(zhí)行任何額外的維護(hù)或記錄,這是一個(gè)好地方。 這不同于onscrollchanged(int,int,int,int),接收距離滾動(dòng)在任一方向在適配器的數(shù)據(jù)集而不是絕對(duì)滾動(dòng)坐標(biāo)。因?yàn)閞ecyclerview無(wú)法計(jì)算絕對(duì)滾動(dòng)位置從數(shù)據(jù)集合中的任意點(diǎn),onscrollchanged總是會(huì)得到當(dāng)前getscrollx()和getscrolly()值不符合設(shè)置滾動(dòng)位置的數(shù)據(jù)。然而,一些子類(lèi)可以選擇使用這些字段作為特殊的偏移量。
Parameters dx horizontal distance scrolled in pixels dy vertical distance scrolled in pixels
public boolean onTouchEvent (MotionEvent e)
public void removeItemDecoration (RecyclerView.ItemDecoration decor)
Remove an RecyclerView.ItemDecoration from this RecyclerView.
The given decoration will no longer impact the measurement and drawing of item views.
Parameters decor Decoration to remove See Also addItemDecoration(ItemDecoration)
public void removeOnChildAttachStateChangeListener (RecyclerView.OnChildAttachStateChangeListener listener)
Removes the provided listener from child attached state listeners list.
Parameters listener Listener to unregister
public void removeOnItemTouchListener (RecyclerView.OnItemTouchListener listener)
Remove an RecyclerView.OnItemTouchListener. It will no longer be able to intercept touch events.
Parameters listener Listener to remove
public void removeOnScrollListener (RecyclerView.OnScrollListener listener)
Remove a listener that was notified of any changes in scroll state or position.
Parameters listener listener to set or null to clear
public void requestChildFocus (View child, View focused)
Called when a child of this parent wants focus
Parameters child The child of this ViewParent that wants focus. This view will contain the focused view. It is not necessarily the view that actually has focus. focused The view that is a descendant of child that actually has focus
public boolean requestChildRectangleOnScreen (View child, Rect rect, boolean immediate)
Called when a child of this group wants a particular rectangle to be positioned onto the screen. ViewGroups overriding this can trust that:
child will be a direct child of this group rectangle will be in the child’s coordinates ViewGroups overriding this should uphold the contract:
nothing will change if the rectangle is already visible the view port will be scrolled only just enough to make the rectangle visible
Parameters child The direct child making the request. rect The rectangle in the child’s coordinates the child wishes to be on the screen. immediate True to forbid animated or delayed scrolling, false otherwise Returns Whether the group scrolled to handle the operation
public void requestDisallowInterceptTouchEvent (boolean disallowIntercept)
Called when a child does not want this parent and its ancestors to intercept touch events with onInterceptTouchEvent(MotionEvent).
This parent should pass this call onto its parents. This parent must obey this request for the duration of the touch (that is, only clear the flag after this parent has received an up or a cancel.
Parameters disallowIntercept True if the child does not want the parent to intercept touch events. public void requestLayout ()
Call this when something has changed which has invalidated the layout of this view. This will schedule a layout pass of the view tree. This should not be called while the view hierarchy is currently in a layout pass (isInLayout(). If layout is happening, the request may be honored at the end of the current layout pass (and then layout will run again) or after the current frame is drawn and the next layout occurs.
Subclasses which override this method should call the superclass method to handle possible request-during-layout errors correctly.
public void scrollBy (int x, int y)
Move the scrolled position of your view. This will cause a call to onScrollChanged(int, int, int, int) and the view will be invalidated.
Parameters x the amount of pixels to scroll by horizontally y the amount of pixels to scroll by vertically
public void scrollTo (int x, int y)
Set the scrolled position of your view. This will cause a call to onScrollChanged(int, int, int, int) and the view will be invalidated.
Parameters x the x position to scroll to y the y position to scroll to
public void scrollToPosition (int position)
Convenience method to scroll to a certain position. RecyclerView does not implement scrolling logic, rather forwards the call to scrollToPosition(int)
Parameters position Scroll to this adapter position See Also scrollToPosition(int)
public void sendAccessibilityEventUnchecked (AccessibilityEvent event)
This method behaves exactly as sendAccessibilityEvent(int) but takes as an argument an empty AccessibilityEvent and does not perform a check whether accessibility is enabled.
If an View.AccessibilityDelegate has been specified via calling setAccessibilityDelegate(AccessibilityDelegate) its sendAccessibilityEventUnchecked(View, AccessibilityEvent) is responsible for handling this call.
Parameters event The event to send.
public void setAccessibilityDelegateCompat (RecyclerViewAccessibilityDelegate accessibilityDelegate)
設(shè)置無(wú)障礙兼容使用的recyclerview通用性實(shí)現(xiàn)。
Parameters accessibilityDelegate The accessibility delegate to be used by RecyclerView.
public void setAdapter (Adapter adapter)
Set a new adapter to provide child views on demand.
When adapter is changed, all existing views are recycled back to the pool. If the pool has only one adapter, it will be cleared.
Parameters adapter The new adapter to set, or null to set no adapter. See Also swapAdapter(Adapter, boolean)
public void setChildDrawingOrderCallback (RecyclerView.ChildDrawingOrderCallback childDrawingOrderCallback)
Sets the RecyclerView.ChildDrawingOrderCallback to be used for drawing children.
See getChildDrawingOrder(int, int) for details. Calling this method will always call setChildrenDrawingOrderEnabled(boolean). The parameter will be true if childDrawingOrderCallback is not null, false otherwise.
Note that child drawing order may be overridden by View’s elevation.
Parameters childDrawingOrderCallback The ChildDrawingOrderCallback to be used by the drawing system.
public void setClipToPadding (boolean clipToPadding)
Sets whether this ViewGroup will clip its children to its padding, if padding is present.
By default, children are clipped to the padding of their parent Viewgroup. This clipping behavior is only enabled if padding is non-zero.
Parameters clipToPadding true to clip children to the padding of the group, false otherwise
public void setHasFixedSize (boolean hasFixedSize)
RecyclerView can perform several optimizations if it can know in advance that changes in adapter content cannot change the size of the RecyclerView itself. If your use of RecyclerView falls into this category, set this to true.
Parameters hasFixedSize true if adapter changes cannot affect the size of the RecyclerView.
public void setItemAnimator (RecyclerView.ItemAnimator animator)
設(shè)置recyclerview.itemanimator將處理涉及的變化在這recyclerview子view動(dòng)畫(huà)。默認(rèn)情況下,recyclerview實(shí)例化和使用defaultitemanimator實(shí)例。無(wú)論項(xiàng)目動(dòng)畫(huà)的recyclerview啟用取決于itemanimator是否支持項(xiàng)目動(dòng)畫(huà)的布局管理器。
Parameters animator The ItemAnimator being set. If null, no animations will occur when changes occur to the items in this RecyclerView.
public void setItemViewCacheSize (int size)
設(shè)置在添加他們的潛在共享再生view池之前保留的屏幕視圖大小。
屏幕視圖緩存保持意識(shí)到連接適配器的變化,讓LayoutManager重復(fù)使用未經(jīng)修改而不需要返回到適配器綁定他們的view。
Parameters size Number of views to cache offscreen before returning them to the general recycled view pool
public void setLayoutManager (RecyclerView.LayoutManager layout)
設(shè)置這recyclerview將使用的recyclerview.layoutmanager。
對(duì)比其他適配器支持的觀點(diǎn)如ListView和GridView,recyclerview允許客戶(hù)端代碼為子視圖的自定義布局安排。這些安排是由recyclerview.layoutmanager控制。一個(gè)布局管理器必須提供recyclerview功能。
幾個(gè)默認(rèn)策略是為常用的使用,如列表和網(wǎng)格。
Parameters layout LayoutManager to use
public void setNestedScrollingEnabled (boolean enabled)
啟用或禁用此視圖嵌套滾動(dòng)。
如果將此屬性設(shè)置為true,則可允許在當(dāng)前層次結(jié)構(gòu)中允許啟動(dòng)嵌套滾動(dòng)操作以兼容父視圖。如果這個(gè)視圖沒(méi)有實(shí)現(xiàn)嵌套滾動(dòng),這將不會(huì)有效果。禁用嵌套滾動(dòng),而嵌套滾動(dòng)正在進(jìn)行中,有停止嵌套滾動(dòng)的效果。
Parameters enabled true to enable nested scrolling, false to disable
public void setRecycledViewPool (RecyclerView.RecycledViewPool pool)
Recycled view pools允許多個(gè)recyclerviews分享不用的view公共池。可如果你有相同的view,使用適配器類(lèi)型多recyclerviews是有用的,例如,如果你在項(xiàng)目視圖的顯示同一種ViewPager有幾個(gè)數(shù)據(jù)集。
Parameters pool Pool to set. If this parameter is null a new pool will be created and used.
public void setRecyclerListener (RecyclerView.RecyclerListener listener)
注冊(cè)一個(gè)監(jiān)聽(tīng)器,當(dāng)子view被回收時(shí),將得到通知。 當(dāng)LayoutManager或recyclerview決定子視圖不再需要時(shí)該監(jiān)聽(tīng)者將被調(diào)用。如果一個(gè)應(yīng)用程序?qū)嘿F的或重量級(jí)的數(shù)據(jù)與項(xiàng)目視圖關(guān)聯(lián),這可能是釋放或釋放這些資源的好地方。
Parameters listener Listener to register, or null to clear
public void setScrollingTouchSlop (int slopConstant)
Configure the scrolling touch slop for a specific use case. Set up the RecyclerView’s scrolling motion threshold based on common usages. Valid arguments are TOUCH_SLOP_DEFAULT and TOUCH_SLOP_PAGING.
Parameters slopConstant One of the TOUCH_SLOP_ constants representing the intended usage of this RecyclerView
public void setViewCacheExtension (RecyclerView.ViewCacheExtension extension)
設(shè)置回收器將被一種新的recyclerview.viewcacheextension使用。
Parameters extension ViewCacheExtension to be used or null if you want to clear the existing one. See Also ERROR(ViewCacheExtension#getViewForPositionAndType(Recycler, int, int)} /{@link ViewCacheExtension#getViewForPositionAndType(Recycler, int, int)})
public void smoothScrollBy (int dx, int dy)
由給定的像素沿任一軸滾動(dòng)滾動(dòng)。
Parameters dx Pixels to scroll horizontally dy Pixels to scroll vertically
public void smoothScrollToPosition (int position)
開(kāi)始一個(gè)平滑滾動(dòng)到適配器指定位置。
支持平滑滾動(dòng),你必須重寫(xiě)smoothscrolltoposition(recyclerview,狀態(tài),int)和創(chuàng)建一個(gè)recyclerview.smoothscroller。 recyclerview.layoutmanager負(fù)責(zé)創(chuàng)建實(shí)際的滾動(dòng)動(dòng)作。如果你想提供一個(gè)自定義平滑滾動(dòng)邏輯,重寫(xiě)smoothscrolltoposition(recyclerview,狀態(tài),int)在你的布局管理器。
Parameters position The adapter position to scroll to See Also smoothScrollToPosition(RecyclerView, State, int)
public boolean startNestedScroll (int axes)
Begin a nestable scroll operation along the given axes.
A view starting a nested scroll promises to abide by the following contract:
The view will call startNestedScroll upon initiating a scroll operation. In the case of a touch scroll this corresponds to the initial ACTION_DOWN. In the case of touch scrolling the nested scroll will be terminated automatically in the same manner as requestDisallowInterceptTouchEvent(boolean). In the event of programmatic scrolling the caller must explicitly call stopNestedScroll() to indicate the end of the nested scroll.
If startNestedScroll returns true, a cooperative parent was found. If it returns false the caller may ignore the rest of this contract until the next scroll. Calling startNestedScroll while a nested scroll is already in progress will return true.
At each incremental step of the scroll the caller should invoke dispatchNestedPreScroll once it has calculated the requested scrolling delta. If it returns true the nested scrolling parent at least partially consumed the scroll and the caller should adjust the amount it scrolls by.
After applying the remainder of the scroll delta the caller should invoke dispatchNestedScroll, passing both the delta consumed and the delta unconsumed. A nested scrolling parent may treat these values differently. See onNestedScroll(View, int, int, int, int).
Parameters axes Flags consisting of a combination of SCROLL_AXIS_HORIZONTAL and/or SCROLL_AXIS_VERTICAL. Returns true if a cooperative parent was found and nested scrolling has been enabled for the current gesture.
public void stopNestedScroll ()
Stop a nested scroll in progress.
Calling this method when a nested scroll is not currently in progress is harmless.
public void stopScroll ()
Stop any current scroll in progress, such as one started by smoothScrollBy(int, int), fling(int, int) or a touch-initiated fling.
public void swapAdapter (Adapter adapter, boolean removeAndRecycleExistingViews)
提供一個(gè)新適配器替換當(dāng)前適配器。它類(lèi)似于setadapter(適配器)但假設(shè)現(xiàn)有的適配器和新的適配器使用相同的recyclerview.viewholder和不明確的recycledviewpool。 注意,還需要onadapterchanged回調(diào)。
Parameters adapter The new adapter to set, or null to set no adapter. removeAndRecycleExistingViews If set to true, RecyclerView will recycle all existing Views. If adapters have stable ids and/or you want to animate the disappearing views, you may prefer to set this to false. See Also setAdapter(Adapter)