Andy Andy - 2 months ago 8
Android Question

Changing WRAP_CONTENT to a set number using LinearLayout.LayoutParams

I have set up some

LinearLayout.LayoutParams
to set up some buttons just using java. But I want to change it from
WRAP_CONTENT
to a height and width of my choice.

//LinearLayout.LayoutParams top;
//this is declared at the top as it is used by different bits of the code.
top = new LinearLayout.LayoutParams
(LinearLayout.LayoutParams.WRAP_CONTENT, LinearLayout.LayoutParams.WRAP_CONTENT);
top.topMargin = 100;
top.leftMargin = 120;

Answer
top = new LinearLayout.LayoutParams
            (90, 80); 

// whatever u like

this is from documentation:

public LayoutParams(int width, int height) {
        super(width, height);
        weight = 0;
    }
Comments