我正在尝试编写一个使用 GridView 显示图像的照片库。图像是从远程位置加载的,我想在加载图像时显示水平进度条。这部分工作正常。我编写了从 BaseAdapter 扩展的自定义适配器。在我的 getView 方法中,我返回 LinearLayout 对象,其中包含 ProgressBar 对象,当图像加载完成时,它会被 ImageView 替换。
所以这是我的问题。与 ImageView 对象相比,进度条很细(高度很小)。发生的事情是当画廊 Activity 开始时我看到很多进度条然后它们开始“扩展”(因为图像高度大于进度条高度)并且它非常丑陋。我想为我在 getView 方法中返回的 LinearLayout 对象设置初始宽度和高度。
谁能帮我实现这个?
这是我的代码:
public class GalleryAdapter extends BaseAdapter{
public View getView(int position, View convertView, ViewGroup parent){
LinearLayout layout = new LinearLayout(activity);
// Some code here to set initial width and height to layout
// This is my image loader that puts progress bar in layout,
// loads image then replaces progrssbar with image
new LoadAndShowImage(imageUrl, layout, onClick, memCache).execute();
return layout;
}
}
最佳答案
我已经以其他方式提出问题并得到了答案。是here
关于android - 将初始大小设置为从 BaseAdapter 的 getView 方法返回的 LinearLayout,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9753231/