我一直在试图重新设置ImageView的大小。 我正在使用自定义适配器。Android:findViewById的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的拇指=(ImageView的)row.findViewById(R.id.bookThumb);在自定义适配器内部,它的工作效果很好,但由于它遍历每一行,因此滚动非常缓慢。
所以...我现在试图让thumb =(ImageView)row.findViewById(R.id.bookThumb);从我的主要活动,并设置其大小,但我得到空,因此应用程序部队关闭。
尝试:
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);
总是空。
感谢任何帮助!感觉就像我失去了一些愚蠢的东西:)
尝试使用'hierarchyviewer'来查看实际上您的视图层次结构的样子。 – 2011-03-20 15:08:20
在你的主要活动中你在做什么?它是否在setContentView被调用之后? – slund 2011-03-20 15:20:58
@Gil,我会尝试使用...谢谢。 @slund,是的,之后。此外,检查任何虚假进口的android.R,关闭ImageView与/>而不是,基本上做了我在谷歌上找到的所有东西:) – 2011-03-20 15:24:17