You are calling getWidth()
too early. The UI has not been sized and laid out on the screen yet.
Try getting size after overriding the onWindowFocusChanged()
function:
@Override
public void onWindowFocusChanged(boolean hasFocus) {
super.onWindowFocusChanged(hasFocus);
//Here you can get the size!
}
Have a look at this discussion
If you want your bitmap to match parent height and width you can use this:
LayoutParams params = new LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT);
imageView.setImageBitmap(bitmap);
imageView.setLayoutParams(params);
Hope this helps :)