felipecsl / AsymmetricGridView

Android ListView that mimics a GridView with asymmetric items. Supports items with row span and column span
http://felipecsl.com/AsymmetricGridView
MIT License
1.84k stars 431 forks source link

Specify row height #47

Closed gayathri-nair03 closed 9 years ago

gayathri-nair03 commented 9 years ago

Is it possible to specify a row height in Asymmetric grid view? I need 'x' dp for small square grids (2 cols in a row) and 'y' dp for one rectangular view (one col in a row). Is this possible?

gayathri-nair03 commented 9 years ago

Never mind. Found a solution to do this.

gonzalomelov commented 9 years ago

How did you do?

rayray commented 8 years ago

@gayathri-nair03 What is the solution?

gayathri-nair03 commented 8 years ago

@gonzalomelov & @rayray - I did not reference this library, instead copied all reqd files into my project, so that I could edit some lines of code, as required. U might also try extending the existing classes, for the same requirement. Anyway, here's how I did it.

  1. Go to class AsymmetricGridViewAdapter
  2. Method - getView()
  3. Towards the end of this method, there is a line of code setting the view's layout params. Something like this: view.setLayoutParams(new LinearLayout.LayoutParams(getRowWidth(currentItem.getItem()), getRowHeight(currentItem.getItem()))); If you observe, here the row height is being set to one particular value - getRowHeight().
  4. You can change this row height to a px value of your own, as I did - //START - Gayatri - Added for specifying row heights if (currentItem.getItem().getRowSpan() == 1) { view.setLayoutParams( new LinearLayout.LayoutParams(getRowWidth(currentItem.getItem()), context.getResources() .getDimensionPixelSize( R.dimen.photo_grid_height))); } else { view.setLayoutParams( new LinearLayout.LayoutParams(getRowWidth(currentItem.getItem()), context.getResources() .getDimensionPixelSize( R.dimen.hor_photo_height))); } //Added block ends here

P.S - I see that this library has undergone a refactoring now, with support for Recycler View. I have worked with the previous version. Hope this helps.