Hitesh Gehlot
Hitesh Gehlot

Reputation: 1347

Android grid layout with circular item in random position

I am trying to implement different grid layout structure but unfortunately not getting success. So please look on below screenshot and tell me is it possible to implement gridview or recyclerview like below screenshot. Thanks in advance :)

enter image description here

Upvotes: 1

Views: 1182

Answers (1)

Naveen Dew
Naveen Dew

Reputation: 1295

Use GridLayoutManager with spancount 3

Now set the custom top margin to your root layout for the second position.

Apply this logic to your RecyclerViewAdapter's onBindViewHolder

if (position % 3 == 1) {
            RelativeLayout.LayoutParams relativeParams = new RelativeLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT);
            relativeParams.setMargins(0, 50, 0, 0);  // left, top, right, bottom
            holder.rel_root.setLayoutParams(relativeParams);
   }

not sure if it's correct way but works :)

output

Upvotes: 3

Related Questions