Android RecyclerView Grid Background

882 views Asked by At

I have an array of images with their respective ids. I want to change the background of the RecyclerView grids by fetching images from this array using their ids.

Image

In this image grid it has dark blue background, and I want to change each grid's background with some random image by fetching their ids from an array. Please help me to do this!

2

There are 2 answers

1
Victor On

You can use Color Pallette and extract color of each image. Each image will be an item in recylerview.
U can use color pallete to extract color and change background. Please async method for faster operation. Use this link as reference: AndroidColorPalette

0
Shunan On

You can simply use grid layout manager, just pass the context and number of columns in grid layout manager's constructor and in the constructor of your recycler view adapter pass the reference of array of images. Then set image on background in onBindViewHolder function of your adapter

Here is a sample code:

GridLayoutManager gridLayoutManager = new GridLayoutManager(SharingPhotoActivity.this, 3);
            if (recyclerView != null) {
                recyclerView.setLayoutManager(gridLayoutManager);
                recyclerView.setItemViewCacheSize(0);
            }
            mAdapter = new imageRecyclerAdapter(SharingPhotoActivity.this, bitmapList, compressUriList, mStorageRef, bitmapModels);
            recyclerView.setAdapter(mAdapter);