cot*_*aws 19
我昨晚必须解决这个问题,这对我有用.它查找子宽度并假设所有单元格具有相同的宽度,将GridView的宽度除以子宽度.(getColumnWidth()在早期的API中也不可用,因此解决方法).
private int getNumColumnsCompat() {
if (Build.VERSION.SDK_INT >= 11) {
return getNumColumnsCompat11();
} else {
int columns = 0;
int children = getChildCount();
if (children > 0) {
int width = getChildAt(0).getMeasuredWidth();
if (width > 0) {
columns = getWidth() / width;
}
}
return columns > 0 ? columns : AUTO_FIT;
}
}
@TargetApi(Build.VERSION_CODES.HONEYCOMB)
private int getNumColumnsCompat11() {
return getNumColumns();
}
Run Code Online (Sandbox Code Playgroud)
但是,有一些重要的限制需要注意.
setHorizontalSpacing().如果你使用水平间距,你可能需要调整它来考虑它.| 归档时间: |
|
| 查看次数: |
15183 次 |
| 最近记录: |