我一直在尝试重新设置 ImageView 的大小。我正在使用自定义适配器。
View row = convertView;
if (row == null) {
LayoutInflater inflater = (LayoutInflater)
context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
row = inflater.inflate(R.layout.grid_item, null);
}
thumb = (ImageView) row.findViewById(R.id.bookThumb);
当我使用 ImageView thumb = (ImageView) row.findViewById(R.id.bookThumb); 在自定义适配器内部它工作得很好,但是因为它循环遍历每一行,所以滚动非常慢。
所以...我现在正在尝试获取 thumb = (ImageView) row.findViewById(R.id.bookThumb); 从我的 Main Activity 并设置它的大小,但我得到 Null,因此应用程序强制关闭。
试过:
LinearLayout layout = (LinearLayout) findViewById(R.id.gridLayout);
ImageView thumbRow = (ImageView)layout.findViewById(R.id.bookThumb);
也试过:
// gv is the gridview (R.id.gridview)
ImageView thumbRow = (ImageView)gv.findViewById(R.id.bookThumb);
始终为空。
感谢任何帮助!感觉就像我错过了一些愚蠢的东西:)