I have created Button View programatically inside LinearLayout with VERTICAL orientation. Below is my code for button view
LinearLayout.LayoutParams params= new LinearLayout.LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT);
int w=Resources.getSystem().getDisplayMetrics().widthPixels;
params.setMargins(w/3,0,w/3,0);
button.setLayoutParams(params);
button.setText("Hello");
layout.setGravity(Gravity.CENTER);
layout.addView(button);
But because of the dimensions ButtonView looks different in some low dimension device.
For ex. below in low dimension
_____
|hello|
|_____|
below in high dimension devices,
_____________
| hello |
|_____________|
When I tried wrap content for width and left, right padding for it. Due to the length of the text inside Button, all ButtonView will not look even.
For Ex.
_____________
| Hello World |
|_____________|
_______
| hello |
|_______|
My goal is to achieve above(mentioned in high dimension) like width for all devices.
Thanks in advance.
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…