0
我有一個裝飾,我添加到我的recyclerView,並在初始加載和方向更改時,裝飾工程很好。當我刪除一個項目時,我希望它根據刪除後項目的新位置進行重新裝訂,但它不起作用。如何重新裝飾recyclerView項目被刪除的項目下
我嘗試添加新的裝飾器,失敗;所以現在
我認爲調用像recyclerView的東西會強制它重繪:它正在執行的代碼,但背景不會改變。
@Override
public void onItemRangeChanged(int positionStart, int
itemCount) {
super.onItemRangeChanged(positionStart, itemCount);
Log.e(TAG, "range start: " + positionStart + " count: " +
itemCount);
Runnable pendingRemovalRunnable = new Runnable() {
@Override
public void run() {
mRecyclerView.invalidateItemDecorations();
Log.d(TAG, "run");
}
};
pendingRemovalRunnable.run();
}
});
這是我的裝飾代碼:
@Override
public void getItemOffsets(Rect outRect, View view, RecyclerView
parent, RecyclerView.State state) {
super.getItemOffsets(outRect, view, parent, state);
int pos = parent.getChildAdapterPosition(view);
if (pos == -1)
return;
String vid = ((RVAdapter)parent.getAdapter()).getVid(pos);
mIsInlist =
PlaylistManager.get(view.getContext()).getIsInPlaylist(vid);
mIsTop = PlaylistManager.get(view.getContext()).getIsTop(vid);
mIsBottom = PlaylistManager.get(view.getContext()).getIsBottom(vid);
mRegularLayout = (LinearLayout)
view.findViewById(R.id.regularLayout);
if (mIsInlist) {
if (mIsTop) {
mRegularLayout.setBackground(ContextCompat
.getDrawable(view.getContext(),
R.drawable.list_selector_playlist_top));
} else { if (mIsBottom) {
mRegularLayout.setBackground(ContextCompat.
getDrawable(view.getContext(),
R.drawable.list_selector_playlist_bottom));
} else {
mRegularLayout.setBackground(
ContextCompat.getDrawable(view.getContext(),
R.drawable.list_selector_playlist)); }
} else {
mRegularLayout.setBackground(ContextCompat.
getDrawable(view.getContext(), R.drawable.list_selector));}
}
你試過這個答案在stackoverflow http://stackoverflow.com/a/26310638/3678308? –