Here is my code
Button myButton = new Button(this);
myButton.setText("Press Me");
myButton.setTextColor(Color.WHITE);
LinearLayout layout = (LinearLayout) findViewById(R.id.linearLayout1);
layout.addView(myButton);
How do I add wrapcontent
to this button?
Use this line (I used FILL_PARENT to demonstrate)
layout.setLayoutParams(new LayoutParams(LayoutParams.FILL_PARENT,
LayoutParams.WRAP_CONTENT));
set the wrap content for button
myButtonsetLayoutParams(new LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT));
or for layout
layout.setLayoutParams(new LayoutParams(LayoutParams.WRAP_CONTENT,LayoutParams.WRAP_CONTENT));
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With