gridview images with different alignment

202 Views Asked by At

Capture.jpg

I need to do something like this . It is similar to staggered gridview but all image has same dimension . How do i do this ?

1

There are 1 best solutions below

0
On BEST ANSWER

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

staggered-layout-manager.jpg