2017-04-07 100 views
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));} 

} 
+0

你试过这个答案在stackoverflow http://stackoverflow.com/a/26310638/3678308? –

回答

0

试试这个,

坐落在的onResume()列表活动的方法你recyclerview适配器。因此,当对recyclerview进行任何更改时,它会再次设置。

希望这会有所帮助。