Harsha M V
Harsha M V

Reputation: 54949

Android Grid Formation

I am looking to accomplish something like this in my app. A grid of 3 items in a row. If there are only two or one item in the last row it should stack next to each other and align to the left and leave the second and the last as empty.

enter image description here

My Main Concern is how to handle this via code for the content that is sent from the server via an API and loop through and build this layout dynamically.

Upvotes: 2

Views: 174

Answers (1)

Amine ABDALKHALKI
Amine ABDALKHALKI

Reputation: 445

try to add to your gridview layout this line

 android:numColumns="3"

if you have 5 elements on your gridview adapter there will be 3 items in one row, on the second row there will be 2 items aligned to the left.

Upvotes: 2

Related Questions