Search code examples
androidviewbitmapmeasure

How do I set the size of my Bitmap to WRAP_CONTENT and FILL_PARENT?


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


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);