Java Code Examples for androidx.recyclerview.widget.RecyclerView#addItemDecoration()
The following examples show how to use
androidx.recyclerview.widget.RecyclerView#addItemDecoration() .
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: HomeActivity.java From SmsCode with GNU General Public License v3.0 | 6 votes |
private void onChooseThemePreferenceClicked() { if (mThemeChooseDialog == null) { ThemeItemAdapter adapter = new ThemeItemAdapter(this, ThemeItemContainer.get().getThemeItemList()); adapter.setOnItemClickListener(mItemClickListener); RecyclerView.LayoutManager layoutManager = new LinearLayoutManager(this); mThemeChooseDialog = new MaterialDialog.Builder(this) .title(R.string.pref_choose_theme_title) .adapter(adapter, layoutManager) .negativeText(R.string.cancel) .build(); RecyclerView recyclerView = mThemeChooseDialog.getRecyclerView(); recyclerView.addItemDecoration(new DividerItemDecoration(this, LinearLayout.VERTICAL)); } mThemeChooseDialog.show(); }
Example 2
Source File: FilePicker.java From a with GNU General Public License v3.0 | 6 votes |
@Override @NonNull protected LinearLayout makeCenterView() { @SuppressLint("InflateParams") LinearLayout rootLayout = (LinearLayout) LayoutInflater.from(activity).inflate(R.layout.view_file_picker, null); RecyclerView recyclerView = rootLayout.findViewById(R.id.rv_file); recyclerView.addItemDecoration(new DividerItemDecoration(activity, LinearLayout.VERTICAL)); recyclerView.setLayoutManager(new LinearLayoutManager(activity)); recyclerView.setAdapter(adapter); emptyView = rootLayout.findViewById(R.id.tv_empty); RecyclerView pathView = rootLayout.findViewById(R.id.rv_path); pathView.setLayoutManager(new LinearLayoutManager(activity, LinearLayout.HORIZONTAL, false)); pathView.setAdapter(pathAdapter); return rootLayout; }
Example 3
Source File: MainActivity.java From Markwon with Apache License 2.0 | 6 votes |
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); // obtain an instance of Markwon // here we are creating as core markwon (no additional plugins are registered) final Markwon markwon = Markwon.create(this); final Adapt adapt = Adapt.create(); final List<Item> items = new ArrayList<>(); final SampleItem.OnClickListener onClickListener = this::showSample; for (Sample sample : Sample.values()) { items.add(new SampleItem(sample, markwon, onClickListener)); } adapt.setItems(items); final RecyclerView recyclerView = findViewById(R.id.recycler_view); recyclerView.setLayoutManager(new LinearLayoutManager(this)); recyclerView.setHasFixedSize(true); recyclerView.addItemDecoration(createSampleItemDecoration()); recyclerView.setAdapter(adapt); }
Example 4
Source File: FavoritesFragment.java From YouTube-In-Background with MIT License | 6 votes |
@Override public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { // Inflate the layout for this fragment View rootView = inflater.inflate(R.layout.fragment_recently_watched, container, false); TextView fragmentListTitle = (TextView) rootView.findViewById(R.id.text_view_title); fragmentListTitle.setText(getResources().getString(R.string.fragment_title_favorite)); recyclerView = (RecyclerView) rootView.findViewById(R.id.recently_played); recyclerView.setLayoutManager(getLayoutManager()); recyclerView.addItemDecoration(getItemDecoration()); recyclerView.getItemAnimator().setAddDuration(500); recyclerView.getItemAnimator().setChangeDuration(500); recyclerView.getItemAnimator().setMoveDuration(500); recyclerView.getItemAnimator().setRemoveDuration(500); videoListAdapter = getAdapter(); videoListAdapter.setOnItemClickListener(this); recyclerView.setAdapter(videoListAdapter); return rootView; }
Example 5
Source File: VideoTutorialsActivity.java From BaldPhone with Apache License 2.0 | 6 votes |
@Override protected void onCreate(@Nullable final Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_help); final RecyclerView recycler_view = findViewById(R.id.recycler_view); final DividerItemDecoration dividerItemDecoration = new DividerItemDecoration(recycler_view.getContext(), DividerItemDecoration.VERTICAL); dividerItemDecoration.setDrawable(getDrawable(R.drawable.ll_divider)); recycler_view.addItemDecoration(dividerItemDecoration); final Resources resources = getResources(); recycler_view.setAdapter( new HelpRecyclerViewAdapter( this, S.typedArrayToResArray(resources, R.array.yt_texts), S.typedArrayToResArray(resources, R.array.yt_logos))); }
Example 6
Source File: ProductGridFragment.java From material-components-android-codelabs with Apache License 2.0 | 5 votes |
@Override public View onCreateView( @NonNull LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { // Inflate the layout for this fragment with the ProductGrid theme View view = inflater.inflate(R.layout.shr_product_grid_fragment, container, false); // Set up the tool bar setUpToolbar(view); // Set up the RecyclerView RecyclerView recyclerView = view.findViewById(R.id.recycler_view); recyclerView.setHasFixedSize(true); GridLayoutManager gridLayoutManager = new GridLayoutManager(getContext(), 2, GridLayoutManager.HORIZONTAL, false); gridLayoutManager.setSpanSizeLookup(new GridLayoutManager.SpanSizeLookup() { @Override public int getSpanSize(int position) { return position % 3 == 2 ? 2 : 1; } }); recyclerView.setLayoutManager(gridLayoutManager); StaggeredProductCardRecyclerViewAdapter adapter = new StaggeredProductCardRecyclerViewAdapter( ProductEntry.initProductEntryList(getResources())); recyclerView.setAdapter(adapter); int largePadding = getResources().getDimensionPixelSize(R.dimen.shr_staggered_product_grid_spacing_large); int smallPadding = getResources().getDimensionPixelSize(R.dimen.shr_staggered_product_grid_spacing_small); recyclerView.addItemDecoration(new ProductGridItemDecoration(largePadding, smallPadding)); // Set cut corner background for API 23+ if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) { view.findViewById(R.id.product_grid) .setBackgroundResource(R.drawable.shr_product_grid_background_shape); } return view; }
Example 7
Source File: InlineDoubleHeaderFragment.java From header-decor with Apache License 2.0 | 5 votes |
@Override protected void setAdapterAndDecor(@NonNull RecyclerView list) { final InlineDoubleHeaderTestAdapter adapter = new InlineDoubleHeaderTestAdapter(requireContext()); decor = new DoubleHeaderDecoration(adapter, true); setHasOptionsMenu(true); list.setAdapter(adapter); list.addItemDecoration(decor, 1); list.addOnItemTouchListener(this); }
Example 8
Source File: GridRecyclerViewFragment.java From cathode with Apache License 2.0 | 5 votes |
@Override protected void addItemDecorations(RecyclerView recyclerView) { GridLayoutManager layoutManager = (GridLayoutManager) recyclerView.getLayoutManager(); if (itemSpacing == null) { final int horizontalSpacing = getHorizontalSpacing(); final int verticalSpacing = getVerticalSpacing(); itemSpacing = new GridLayoutItemSpacing(layoutManager, horizontalSpacing, verticalSpacing); } recyclerView.addItemDecoration(itemSpacing); }
Example 9
Source File: FrageMyTopic.java From Ruisi with Apache License 2.0 | 5 votes |
@Override public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { super.onCreateView(inflater, container, savedInstanceState); Bundle bundle = getArguments();//从activity传过来的Bundle int uid = 0; if (bundle != null) { uid = bundle.getInt("uid", 0); String username = bundle.getString("username", "我的"); if (uid == 0) { title = "我的帖子"; } else { title = username + "的帖子"; } } initToolbar(true, title); RecyclerView recyclerView = mRootView.findViewById(R.id.recycler_view); recyclerView.setHasFixedSize(true); SwipeRefreshLayout refreshLayout = mRootView.findViewById(R.id.refresh_layout); refreshLayout.setEnabled(false); String myUid = App.getUid(getActivity()); url = "home.php?mod=space&uid=" + (uid > 0 ? uid : myUid) + "&do=thread&view=me&mobile=2"; datas = new ArrayList<>(); adapter = new MyPostsListAdapter(getActivity(), datas); LinearLayoutManager layoutManager = new LinearLayoutManager(getActivity()); recyclerView.addItemDecoration(new MyListDivider(getActivity(), MyListDivider.VERTICAL)); recyclerView.addOnScrollListener(new LoadMoreListener(layoutManager, this, 10)); recyclerView.setLayoutManager(layoutManager); recyclerView.setAdapter(adapter); refresh(); return mRootView; }
Example 10
Source File: MainActivity.java From SugarAdapter with Apache License 2.0 | 5 votes |
@Override protected void onCreate(@Nullable Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); RecyclerView recyclerView = findViewById(R.id.recycler); recyclerView.setLayoutManager(new LinearLayoutManager(this)); recyclerView.addItemDecoration(new DividerItemDecoration(this, RecyclerView.VERTICAL)); // Choose one of usage example simpleUsageExample(recyclerView); // singleDataMultiHolderExample(recyclerView); // sugarHolderListenerExample(recyclerView); // lifecycleAwareExample(recyclerView); }
Example 11
Source File: ModifyAndDeleteActivity.java From DeviceConnect-Android with MIT License | 5 votes |
private void updateDeviceList() { mListAdapter = new ListAdapter<>( mSwitchBotMessageService.getDeviceList(), R.layout.list_modify_and_delete_row, this); RecyclerView deviceList = findViewById(R.id.list_device); deviceList.setHasFixedSize(true); deviceList.setLayoutManager(new LinearLayoutManager(this)); deviceList.addItemDecoration(new DividerItemDecoration(this, DividerItemDecoration.VERTICAL)); deviceList.setAdapter(mListAdapter); }
Example 12
Source File: OngoingGameFragment.java From PretendYoureXyzzyAndroid with GNU General Public License v3.0 | 5 votes |
private void showPlayers() { if (manager == null || getContext() == null) return; RecyclerView recyclerView = new RecyclerView(getContext()); recyclerView.setLayoutManager(new LinearLayoutManager(getContext(), RecyclerView.VERTICAL, false)); recyclerView.addItemDecoration(new DividerItemDecoration(getContext(), DividerItemDecoration.VERTICAL)); recyclerView.setAdapter(new PlayersAdapter(getContext(), manager.players(), this)); MaterialAlertDialogBuilder builder = new MaterialAlertDialogBuilder(getContext()); builder.setTitle(R.string.playersLabel) .setView(recyclerView) .setPositiveButton(android.R.string.ok, null); DialogUtils.showDialog(getActivity(), builder); }
Example 13
Source File: RxLinearActivity.java From MultiTypeRecyclerViewAdapter with Apache License 2.0 | 5 votes |
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); setTitle("Rx线性排布"); RecyclerView recyclerView = (RecyclerView) findViewById(R.id.recyclerview); textView1 = (TextView) findViewById(R.id.text1); textView2 = (TextView) findViewById(R.id.text2); textView3 = (TextView) findViewById(R.id.text3); textView4 = (TextView) findViewById(R.id.text4); helper = new RxAdapterHelper(); SimpleRxHelperAdapter adapter = new SimpleRxHelperAdapter(helper); recyclerView.setLayoutManager(new LinearLayoutManager(this)); recyclerView.addItemDecoration(new StickyHeaderDecoration(adapter)); recyclerView.setAdapter(adapter); helper.notifyLoadingDataAndHeaderChanged(SimpleHelper.LEVEL_THIRD, 3); textView3.postDelayed(() -> { Random random = new Random(); int rand = random.nextInt(6); List<MultiHeaderEntity> list = new ArrayList<>(); for (int i = 0, size = rand + 1; i < size; i++) { list.add(new ThirdItem(String.format(Locale.getDefault(), "我是第三种类型%d", i), 12 + i)); } textView3.setText(String.format(Locale.getDefault(), "类型3的数量:%d", list.size())); helper.notifyModuleDataAndHeaderChanged(list, new HeaderThirdItem("我是第三种类型的头", IDUtil.getId()), SimpleHelper.LEVEL_THIRD); }, 3000); }
Example 14
Source File: CreditsActivity.java From BaldPhone with Apache License 2.0 | 5 votes |
@Override protected void onCreate(@Nullable Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_credits); RecyclerView recyclerView = findViewById(R.id.recycler_view); names = getResources().getStringArray(R.array.names); tasks = getResources().getStringArray(R.array.tasks); recyclerView.setAdapter(new CreditsAdapter()); final DividerItemDecoration dividerItemDecoration = new DividerItemDecoration(recyclerView.getContext(), DividerItemDecoration.VERTICAL); dividerItemDecoration.setDrawable(Objects.requireNonNull(getDrawable(R.drawable.ll_divider))); recyclerView.addItemDecoration(dividerItemDecoration); }
Example 15
Source File: S.java From BaldPhone with Apache License 2.0 | 5 votes |
public static void showDropDownPopup(BaldActivity baldActivity, int windowsWidth, DropDownRecyclerViewAdapter.DropDownListener dropDownListener, View view) { final RelativeLayout dropDownContainer = (RelativeLayout) LayoutInflater.from(baldActivity).inflate(R.layout.drop_down_recycler_view, null, false); final RecyclerView recyclerView = dropDownContainer.findViewById(R.id.recycler_view); recyclerView.setLayoutManager(new LinearLayoutManager(baldActivity) { @Override public boolean canScrollVertically() { return false; } }); final PopupWindow popupWindow = new PopupWindow(dropDownContainer, (int) (windowsWidth / 1.3), (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, 82 * dropDownListener.size(), baldActivity.getResources().getDisplayMetrics()), true); recyclerView.addItemDecoration( new HorizontalDividerItemDecoration.Builder(baldActivity) .drawable(R.drawable.settings_divider) .build() ); recyclerView.setAdapter(new DropDownRecyclerViewAdapter(baldActivity, popupWindow, dropDownListener)); final ViewGroup root = (ViewGroup) baldActivity.getWindow().getDecorView().getRootView(); if (root == null) throw new AssertionError(); popupWindow.setOnDismissListener(() -> { S.clearDim(root); dropDownListener.onDismiss(); }); popupWindow.setBackgroundDrawable(baldActivity.getDrawable(R.drawable.empty)); popupWindow.showAsDropDown(view); baldActivity.autoDismiss(popupWindow); S.applyDim(root); }
Example 16
Source File: SaveActivity.java From Chimee with MIT License | 5 votes |
private void setupRecyclerView(List<String> files) { RecyclerView recyclerView = findViewById(R.id.rv_document_list); LinearLayoutManager horizontalLayoutManager = new LinearLayoutManager(this, LinearLayoutManager.HORIZONTAL, false); recyclerView.setLayoutManager(horizontalLayoutManager); DividerItemDecoration dividerItemDecoration = new DividerItemDecoration(recyclerView.getContext(), horizontalLayoutManager.getOrientation()); recyclerView.addItemDecoration(dividerItemDecoration); adapter = new SimpleListRvAdapter(this, files); adapter.setClickListener(this); recyclerView.setAdapter(adapter); }
Example 17
Source File: MainActivity.java From tap-android-sdk with Apache License 2.0 | 5 votes |
private void initRecyclerView() { RecyclerView recyclerView = findViewById(R.id.recyclerView); recyclerView.setHasFixedSize(true); RecyclerView.LayoutManager layoutManager = new LinearLayoutManager(this); recyclerView.setLayoutManager(layoutManager); List<TapListItem> listItems = new ArrayList<>(); adapter = new RecyclerViewAdapter(listItems); recyclerView.addItemDecoration(new DividerItemDecoration(this,LinearLayoutManager.VERTICAL)); recyclerView.setAdapter(adapter); }
Example 18
Source File: GithubFragment.java From RendererRecyclerViewAdapter with Apache License 2.0 | 4 votes |
@Nullable @Override public View onCreateView(final LayoutInflater inflater, @Nullable final ViewGroup container, @Nullable final Bundle savedInstanceState) { View inflate = inflater.inflate(R.layout.fragment_github, container, false); mGithubPresenter = new GithubPresenter( getUIRouter(), getMenuController(), MainManager.getInstance().getStargazersManager(), MainManager.getInstance().getForksManager(), mMainPresenterView ); mSwipeToRefresh = (SwipeRefreshLayout) inflate.findViewById(R.id.refresh); mSwipeToRefresh.setOnRefreshListener(() -> mGithubPresenter.onRefresh()); mRecyclerViewAdapter = new RendererRecyclerViewAdapter(); mRecyclerViewAdapter.setDiffCallback(new ItemsDiffCallback()); mRecyclerViewAdapter.registerRenderer(new LoadMoreViewBinder(R.layout.item_load_more)); mRecyclerViewAdapter.registerRenderer(createStargazerRenderer(R.layout.item_user_full_width)); mRecyclerViewAdapter.registerRenderer(createListRenderer() .registerRenderer(createForkRenderer()) .registerRenderer(createStargazerRenderer(R.layout.item_user_150)) ); mRecyclerViewAdapter.registerRenderer(new ViewBinder<>( R.layout.item_category, CategoryModel.class, (model, finder, payloads) -> finder .find(R.id.title, (ViewProvider<TextView>) view -> view.setText(model.getName())) .setOnClickListener(R.id.viewAll, (v -> mGithubPresenter.onCategoryClicked(model))) )); mLayoutManager = new GridLayoutManager(getContext(), MAX_SPAN_COUNT); mLayoutManager.setSpanSizeLookup(new GridLayoutManager.SpanSizeLookup() { @Override public int getSpanSize(final int position) { final Type type = mRecyclerViewAdapter.getType(position); if (type.equals(ForkModel.class) || type.equals(StargazerModel.class)) { return 1; } return 3; } }); mRecyclerView = (RecyclerView) inflate.findViewById(R.id.recycler_view); mRecyclerView.setLayoutManager(mLayoutManager); mRecyclerView.setAdapter(mRecyclerViewAdapter); mRecyclerView.addItemDecoration(new MyItemDecoration()); mRecyclerView.addOnScrollListener(new EndlessScrollListener() { @Override public void onLoadMore(final int page, final int totalItemsCount) { mGithubPresenter.onLoadMore(); } }); return inflate; }
Example 19
Source File: BehaviorActivity.java From PagerBottomTabStrip with Apache License 2.0 | 4 votes |
@Override public void onViewCreated(@NonNull View view, @Nullable Bundle savedInstanceState) { RecyclerView recyclerView = view.findViewById(R.id.recyclerView); recyclerView.setAdapter(new TestAdapter()); recyclerView.addItemDecoration(new DividerItemDecoration(view.getContext(), DividerItemDecoration.VERTICAL)); }
Example 20
Source File: RecyclerViewBindingAdapters.java From Jockey with Apache License 2.0 | 4 votes |
@BindingAdapter("itemDecorations") public static void setItemDecorations(RecyclerView recyclerView, ItemDecoration... decor) { for (ItemDecoration decoration : decor) { recyclerView.addItemDecoration(decoration); } }