First I have a custom component, which is show pictures from the web. It's a simple layout and include a circle progressbar and an ImageView. In the default state the progressbar is visible and it's showing while picture downloading and when it's finished I hide the progressbar and show the picture in the ImageView. It's working very well, but int he emulator and on HTC Hero I got java.lang.OutOfMemoryError: bitmap size exceeds VM budget error. I found the solution here. But my problem, that the TARGET_WIDTH and TARGET_HEIGHT not fix, sometimes 60x90, sometimes fill_parent x fill_parent, and I can't calculate this values in the decode function. For example I added my view in the xml with layout_width="fill_parent" and use in Activity
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
ImageLoader picture = (ImageLoader) findViewById(R.id.picture);
picture.load("http://winportal.net/images/galleries/wallpapers/Earth.jpg");
and in the load method I call the decode function from the solution and try here calculate sizes:
...
this.onMeasure(0, 0);
Log.d("Log", "Layout width: " + this.getMeasuredWidth());
TARGET_WIDTH = this.getMeasuredWidth();
...
and the result is: "Layout width: 24"
I don't understand why got 24 bacause is the width of progressbar, but the layout - which is include it - is fill_parent width. I tried override onMeasure method but got 0.
@Override
protected void onMeasure(final int widthMeasureSpec, final int heightMeasureSpec) {
super.onMeasure(widthMeasureSpec, heightMeasureSpec);
int parentWidth = MeasureSpec.getSize(widthMeasureSpec);
int parentHeight = MeasureSpec.getSize(heightMeasureSpec);
this.setMeasuredDimension(parentWidth, parentHeight);
}
I tried override onSizeChanged too. It's give good values but it's run later, after decode :(
How can I calculate my layout size?