DividerItemDecoration
为什么我的Android中
DividerItemDecoration
是红色的,我引入了哇
为什么我的Android中
DividerItemDecoration
是红色的,我引入了哇
2019-12-17
你对比下我的 import android.graphics.Rect; import android.support.annotation.NonNull; import android.support.v7.widget.RecyclerView; import android.view.View; import android.widget.LinearLayout; public class GridSpaceltemDecoration extends RecyclerView.ItemDecoration { private int mSpace; public GridSpaceltemDecoration(int space,RecyclerView parent) { mSpace=space; getRecyclerViewOffsets(parent); } /** * * @param outRect Item的矩形边界 * @param view ItemView * @param parent RecyclerView * @param state RecyclerView的状态 */ @Override public void getItemOffsets(@NonNull Rect outRect, @NonNull View view, @NonNull RecyclerView parent, @NonNull RecyclerView.State state) { super.getItemOffsets(outRect, view, parent, state); outRect.left=mSpace; } private void getRecyclerViewOffsets(RecyclerView parent) { // View margin, // margin 为正,则View 会距离边界产生一个距离 // margin 为负,则View 会超出边界产生一个距离 LinearLayout.LayoutParams layoutParams=(LinearLayout.LayoutParams)parent.getLayoutParams(); layoutParams.leftMargin=-mSpace; parent.setLayoutParams(layoutParams); } }
举报