You can define a LayoutParams to your button, where you can programmatically define width and height, by means of the properties MATCH_PARENT
or 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, such as 500 px wide and 500 px high, in addition to weight (last parameter):
LinearLayout.LayoutParams buttonLayoutParams = new LinearLayout.LayoutParams(500, 500, 1.0f);
In this way you can progamatically define weight properties, as well as width and something to your views: