You can define a LayoutParams to your button, where you can programmatically define width and height, through the MATCH_PARENTor properties WRAP_CONTENT, in addition to the weight (last parameter):
LinearLayout.LayoutParams buttonLayoutParams = new LinearLayout.LayoutParams(LinearLayout.LayoutParams.MATCH_PARENT, LinearLayout.LayoutParams.WRAP_CONTENT, 1.0f);
you can even define width and height in pixels, for example 500 px width and 500 px height, in addition to the weight (last parameter):
LinearLayout.LayoutParams buttonLayoutParams = new LinearLayout.LayoutParams(500, 500, 1.0f);
This way you can programmatically define weight properties, as well as width and something to your views:
You can define a LayoutParams to your button, where you can programmatically define width and height, through the
MATCH_PARENT
or propertiesWRAP_CONTENT
, in addition to the weight (last parameter):you can even define width and height in pixels, for example 500 px width and 500 px height, in addition to the weight (last parameter):
This way you can programmatically define weight properties, as well as width and something to your views:
You must do it with the LayoutParams property.
So :
According to the Android Documentation the constructor signature is as follows.
Sources: StackOverflow Android Doc's