0

How to control the size of cell in dynamic gridview to resize the cell item to take wrap_content by Java?

ArrayAdapter<String> adp = new ArrayAdapter<String> (this, android.R.layout.simple_dropdown_item_1line, list);
grid.setNumColumns(8);
grid.setBackgroundColor(Color.GRAY);
grid.setColumnWidth(100);
//grid.setFastScrollEnabled(true);
grid.setOverScrollMode(View.OVER_SCROLL_IF_CONTENT_SCROLLS);
//grid.getMeasuredWidth();
grid.setMinimumWidth(100);
grid.setHorizontalFadingEdgeEnabled(true);
grid.setAdapter(adp);
balance_layout.addView(grid);
Unheilig
  • 16,196
  • 193
  • 68
  • 98
  • http://stackoverflow.com/questions/5690144/how-can-i-force-a-gridview-to-use-the-whole-screen-regardless-of-display-size read this topic, it might provide some answers – Chris K. Apr 16 '15 at 10:22

1 Answers1

0
grid.getChildAt(position).getLayoutParams.width = YOUR_SIZE;

You may need to call

grid.invalidate();

to force grid redraw itself.

I would suggest you use some library to let you have a feature like you want or create a custom adapter and chage width with this technique in getView method.

Emre Aktürk
  • 3,306
  • 2
  • 18
  • 30