2015-04-16 127 views
0

如何通過動態控制動態的單元格大小gridview 來調整單元格的大小以獲取wrap_contentAndroid動態網格視圖

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); 
+0

http://stackoverflow.com/questions/5690144/how-can-i-force-a-gridview-to-use-the-whole-screen-regardless-of-display-size閱讀本主題,它可能會提供一些答案 –

回答

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

您可能需要調用

grid.invalidate(); 

給力格重繪自身。

我建議你使用一些庫來讓你有一個像你想要的功能,或者在getView方法中用這種技術創建一個自定義的適配器和chage寬度。