How to change the width of a Button programmatically. I am able to change the height but the width does not change. Following is my code snippet
private void createButton(final String label)
{
Button button = new Button(this);
button.setText(label);
button.setWidth(10);
button.setHeight(100);
button.setOnClickListener(new OnClickListener()
{
@Override
public void onClick(View v)
{
}
});
mMenuContainer.addView(button, mMenuItemLayoutParamters);
}
But the width of the Button occupies the width of the screen.
button.setLayoutParams(new LinearLayout.LayoutParams(10, 100));Should have work for you.
There is one Awesome Example online for this : check this
you should apply
LayoutParamsof theViewGroupthat contains yourView. That is, if your button is insideRelativeLayout, you should useRelativeLayout.LayoutParams