Java Code Examples for androidx.recyclerview.widget.RecyclerView#ItemDecoration

The following examples show how to use androidx.recyclerview.widget.RecyclerView#ItemDecoration . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: OmegaRecyclerView.java    From OmegaRecyclerView with MIT License 6 votes vote down vote up
public void setDividerAlpha(float dividerAlpha) {
    if (0 > dividerAlpha || dividerAlpha > 1) return;

    if (mDividerItemDecoration != null) {
        mDividerItemDecoration.setDividerAlpha(dividerAlpha);
    }

    boolean hasDividerDecoration = false;
    for (int i = 0; i < getItemDecorationCount(); i++) {
        RecyclerView.ItemDecoration itemDecoration = getItemDecorationAt(i);
        if (itemDecoration instanceof DividerItemDecoration) {
            hasDividerDecoration = true;
            invalidateItemDecorations();
            break;
        }
    }

    if (!hasDividerDecoration && mDividerItemDecoration != null) {
        addItemDecoration(mDividerItemDecoration);
    }
}
 
Example 2
Source File: CompositeViewRenderer.java    From RendererRecyclerViewAdapter with Apache License 2.0 6 votes vote down vote up
@NonNull
@Override
public VH createViewHolder(final ViewGroup parent) {
	final RendererRecyclerViewAdapter adapter = createAdapter();
	for (final ViewRenderer renderer : mRenderers) {
		adapter.registerRenderer(renderer);
	}

	final VH viewHolder = createCompositeViewHolder(parent);
	viewHolder.setAdapter(adapter);

	if (viewHolder.getRecyclerView() != null) {
		viewHolder.getRecyclerView().setLayoutManager(createLayoutManager());
		viewHolder.getRecyclerView().setAdapter(adapter);
		viewHolder.getRecyclerView().setRecycledViewPool(mRecycledViewPool);
		for (final RecyclerView.ItemDecoration itemDecoration : createItemDecorations()) {
			viewHolder.getRecyclerView().addItemDecoration(itemDecoration);
		}
	}

	return viewHolder;
}
 
Example 3
Source File: RecyclerViewBindingAdapter.java    From deagle with Apache License 2.0 5 votes vote down vote up
@BindingAdapter({"item_touch"})
public static void setItemTouchHelper(final RecyclerView view, final ItemTouchHelper helper) {
	for (int i = 0;; i ++) try {
		final RecyclerView.ItemDecoration decoration = view.getItemDecorationAt(i);
		if (decoration == null) break;								// Null is returned on RecyclerView library 27+
		if (decoration == helper) return;
	} catch (final IndexOutOfBoundsException ignored) { break; }	// IndexOutOfBoundsException is thrown on RecyclerView library prior to 27.
	helper.attachToRecyclerView(view);
}
 
Example 4
Source File: CardViewActivity.java    From SwipeRecyclerView with Apache License 2.0 5 votes vote down vote up
@Override
protected RecyclerView.ItemDecoration createItemDecoration() {
    return new RecyclerView.ItemDecoration() {
        @Override
        public void getItemOffsets(@NonNull Rect outRect, @NonNull View view, @NonNull RecyclerView parent,
            @NonNull RecyclerView.State state) {
            outRect.set(20, 20, 20, 20);
        }
    };
}
 
Example 5
Source File: CompositeViewBinder.java    From RendererRecyclerViewAdapter with Apache License 2.0 5 votes vote down vote up
public CompositeViewBinder(final int layoutID,
                           @IdRes final int recyclerViewID,
                           @NonNull final Class<M> type,
                           @NonNull final List<? extends RecyclerView.ItemDecoration> decorations) {
	this(layoutID, recyclerViewID, type);
	mDecorations.addAll(decorations);
}
 
Example 6
Source File: AutoPlaylistEditViewModel.java    From Jockey with Apache License 2.0 5 votes vote down vote up
@Bindable
public RecyclerView.ItemDecoration[] getItemDecorations() {
    return new RecyclerView.ItemDecoration[] {
            new BackgroundDecoration(),
            new DividerDecoration(getContext())
    };
}
 
Example 7
Source File: CompositeViewBinder.java    From RendererRecyclerViewAdapter with Apache License 2.0 5 votes vote down vote up
/**
 * Please use a constructor without Context
 */
@Deprecated
public CompositeViewBinder(final int layoutID,
                           @IdRes final int recyclerViewID,
                           @NonNull final Class<M> type,
                           @NonNull final Context context,
                           @NonNull final List<? extends RecyclerView.ItemDecoration> decorations) {
	this(layoutID, recyclerViewID, type, context);
	mDecorations.addAll(decorations);
}
 
Example 8
Source File: GridRecyclerFragmentWithDecorator.java    From aptoide-client-v8 with GNU General Public License v3.0 5 votes vote down vote up
@CallSuper @Override public void setupViews() {
  super.setupViews();
  RecyclerView.ItemDecoration itemDecoration = getItemDecoration();
  if (itemDecoration != null) {
    getRecyclerView().addItemDecoration(itemDecoration);
  }
}
 
Example 9
Source File: RecyclerMessageView.java    From CommonUtils with Apache License 2.0 4 votes vote down vote up
public void addDecoration(@NonNull RecyclerView.ItemDecoration decor) {
    list.addItemDecoration(decor);
}
 
Example 10
Source File: SelectDeviceDialog.java    From EFRConnect-android with Apache License 2.0 4 votes vote down vote up
@Override
public void onAttach(Context context) {
    super.onAttach(context);

    adapter = new ScannedDevicesAdapter(new DeviceInfoViewHolder.Generator(R.layout.device_item) {
        @Override
        public DeviceInfoViewHolder generate(View itemView) {
            final ViewHolder holder = new ViewHolder(itemView);
            holder.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View v) {
                    int adapterPos = holder.getAdapterPosition();
                    if (adapterPos != RecyclerView.NO_POSITION) {
                        BluetoothDeviceInfo devInfo = (BluetoothDeviceInfo) adapter.getDevicesInfo().get(adapterPos);
                        connect(devInfo);
                    }
                }
            });
            return holder;
        }

    }, context);

    discovery = new Discovery(adapter, this);

    adapter.setThermometerMode();

    discovery.connect(context);

    layout = new GridLayoutManager(context, context.getResources().getInteger(R.integer.device_selection_columns), LinearLayoutManager.VERTICAL, false);
    itemDecoration = new RecyclerView.ItemDecoration() {
        final int horizontalMargin = getResources().getDimensionPixelSize(R.dimen.item_margin);

        @Override
        public void getItemOffsets(Rect outRect, View view, RecyclerView parent, RecyclerView.State state) {
            final int columns = layout.getSpanCount();
            if (columns == 1) {
                outRect.set(0, 0, 0, 0);
            } else {
                int itemPos = parent.getChildAdapterPosition(view);
                if (itemPos % columns == columns - 1) {
                    outRect.set(0, 0, 0, 0);
                } else {
                    outRect.set(0, 0, horizontalMargin, 0);
                }
            }
        }
    };
}
 
Example 11
Source File: FavoritesFragment.java    From YouTube-In-Background with MIT License 4 votes vote down vote up
@Override
protected RecyclerView.ItemDecoration getItemDecoration()
{
    //We must draw dividers ourselves if we want them in a list
    return new DividerDecoration(getActivity());
}
 
Example 12
Source File: RecyclerViewHeader.java    From UltimateRecyclerView with Apache License 2.0 4 votes vote down vote up
private void setDecor(RecyclerView.ItemDecoration decor) {
    mDecoration = decor;
}
 
Example 13
Source File: CompositeViewRenderer.java    From RendererRecyclerViewAdapter with Apache License 2.0 4 votes vote down vote up
@NonNull
protected List<? extends RecyclerView.ItemDecoration> createItemDecorations() {
	return new ArrayList<>();
}
 
Example 14
Source File: RecyclerViewRenderer.java    From RendererRecyclerViewAdapter with Apache License 2.0 4 votes vote down vote up
@NonNull
@Override
protected List<? extends RecyclerView.ItemDecoration> createItemDecorations() {
	return Collections.singletonList(new BetweenSpacesItemDecoration(0, 10));
}
 
Example 15
Source File: UltimateRecyclerView.java    From UltimateRecyclerView with Apache License 2.0 4 votes vote down vote up
public void removeItemDecoration(RecyclerView.ItemDecoration decoration) {
    mRecyclerView.removeItemDecoration(decoration);
}
 
Example 16
Source File: PlaylistFragment.java    From YouTube-In-Background with MIT License 4 votes vote down vote up
protected RecyclerView.ItemDecoration getItemDecoration()
{
    //We must draw dividers ourselves if we want them in a list
    return new DividerDecoration(getActivity());
}
 
Example 17
Source File: RecyclerViewHeader.java    From UltimateRecyclerView with Apache License 2.0 4 votes vote down vote up
public static RecyclerViewHeader fromXml(Context context, @LayoutRes int layoutRes, RecyclerView.ItemDecoration decoration) {
    RecyclerViewHeader header = new RecyclerViewHeader(context);
    View.inflate(context, layoutRes, header);
    header.setDecor(decoration);
    return header;
}
 
Example 18
Source File: UltimateRecyclerView.java    From UltimateRecyclerView with Apache License 2.0 2 votes vote down vote up
/**
 * Add an {@link RecyclerView.ItemDecoration} to this RecyclerView. Item decorations can affect both measurement and drawing of individual item views.
 * <p>Item decorations are ordered. Decorations placed earlier in the list will be run/queried/drawn first for their effects on item views. Padding added to views will be nested; a padding added by an earlier decoration will mean further item decorations in the list will be asked to draw/pad within the previous decoration's given area.</p>
 *
 * @param itemDecoration Decoration to add
 * @param index          Position in the decoration chain to insert this decoration at. If this value is negative the decoration will be added at the end.
 */
public void addItemDecoration(RecyclerView.ItemDecoration itemDecoration, int index) {
    mRecyclerView.addItemDecoration(itemDecoration, index);
}
 
Example 19
Source File: LoopBarView.java    From LoopBar with MIT License 2 votes vote down vote up
/**
 * Remove an {@link RecyclerView.ItemDecoration} from wrapped RecyclerView.
 * <p>
 * <p>The given decoration will no longer impact the measurement and drawing of
 * item views.</p>
 *
 * @param decor Decoration to remove
 * @see #addItemDecoration(RecyclerView.ItemDecoration)
 */
@SuppressWarnings("unused")
public final void removeItemDecoration(RecyclerView.ItemDecoration decor) {
    getRvCategories().removeItemDecoration(decor);
}
 
Example 20
Source File: LoopBarView.java    From LoopBar with MIT License 2 votes vote down vote up
/**
 * Add an {@link RecyclerView.ItemDecoration} to wrapped RecyclerView. Item decorations can
 * affect both measurement and drawing of individual item views.
 * <p>
 * <p>Item decorations are ordered. Decorations placed earlier in the list will
 * be run/queried/drawn first for their effects on item views. Padding added to views
 * will be nested; a padding added by an earlier decoration will mean further
 * item decorations in the list will be asked to draw/pad within the previous decoration's
 * given area.</p>
 *
 * @param decor Decoration to add
 */
@SuppressWarnings("unused")
public final void addItemDecoration(RecyclerView.ItemDecoration decor) {
    getRvCategories().addItemDecoration(decor);
}