获取BaseAdapter.getView()中的视图大小

时间:2013-02-08 13:38:31

标签: android

我有一个包含ListView的活动,列表是左边的缩略图,右边是一些文字,非常像联系人列表。
enter image description here
事情是,缩略图从sdcard的绝对路径加载,每个图像大小约为5mb。为了避免内存不足,我在这个tutorial中创建了类,它只加载了图像的缩放版本,并且不占用大量内存。

那么,问题是什么?因为,我必须传递我想要调整图像大小的宽度和高度(以px为单位),但对于不同的设备,我在设置绝对值时会遇到问题。所以,我只是尝试通过args传递视图,并在我的类中操作它以获得宽度和高度,好吧?好吧,但它没有用,因为缩略图还没画得好(我猜),我不能拿他的尺码值。

如何从我的lisview适配器获取方法getView()中的大小?

/** short passage of getView() method */
ImageView image = (ImageView) view.findViewById(R.id.image_thumb);
Bitmap bMap = BitmapAdjusted.decodeSampleBitmap("/sdcardpath/", 
            image); // "image" is the view passed by args
image.setImageBitmap(bMap);

问题在于:

public static decodeSimpleBitmap(String path, View view){
    /** unworth previous code */
    int width = view.getWidth(); // always give zero, getMeasuredWidth() too
    int height = view.getHeight(); // always give zero
    // options is BitmapFactory.Options class, declared before that do the magic
    options.inSampleSize = calculateInSampleSize(options, width, height);

}

谢谢!

0 个答案:

没有答案
相关问题