I need to do something like this . It is similar to staggered gridview but all image has same dimension . How do i do this ?
Asked
Active
Viewed 181 times
0
-
Have a look at RecyclerView and in particular RecyclerView.LayoutManager – Doron Yakovlev Golani Jan 04 '17 at 18:04
1 Answers
1
Finally got it . The trick is to use staggered gridview of spancount 2 and have the second and last image to be of different height then all other . Here is an example .
First get the screen width .
WindowManager wm = (WindowManager) activity.getSystemService(Context.WINDOW_SERVICE);
Display display = wm.getDefaultDisplay();
Point size = new Point();
display.getSize(size);
screenWidth = size.x;
Now set the images in onBindViewHolder .
public void onBindViewHolder(final CustomRecycleViewHolder holder, final int position) {
final Holder myHolder = (Holder) holder;
BitmapFactory.Options opts = new BitmapFactory.Options();
opts.inJustDecodeBounds = true;
BitmapFactory.decodeFile(images.get(position), opts);
opts.inJustDecodeBounds = false;
int height;
if (position == 1 || position == (images.size() - 1)) {
height = 150;
} else {
height = 300;
}
Picasso.with(activity)
.load(images.get(position))
.error(R.drawable.ic_empty)
.placeholder(R.drawable.ic_launcher)
.resize(screenWidth / 2, height)
.centerCrop()
.into((myHolder.images));
}
Result

randy
- 765
- 7
- 24