Question

right now I am setting the width and height staticly like this:

    myBitmap = Bitmap.createBitmap(300, 400, Bitmap.Config.ARGB_8888);

How can I get it so the width is FILL_PARENT and the height is WRAP_CONTENT

I have been looking online and am confused by all the options available. There's setLayoutParams(), onMeasure(), setMinimumWidth(), etc....

Can someone point me in the right direction?

I am making the bitmap inside a custom view that is inside my main activity.

Thanks

Was it helpful?

Solution

I would create LayoutParams to do this.

This or this might be helpful.

Edited, more detail:

    LayoutParams params = new LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.WRAP_CONTENT);
    ImageView iv = new ImageView(this);
    iv.setImageBitmap(myBitmap);
    iv.setLayoutParams(params);
    customView.addView(iv);
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top