In my app I have a screen with four buttons, aligned one on top of the other. The text of these buttons depends on what the user has entered, so I do not know which button is the biggest.
I want to align them so that the left sides of the buttons are all aligned with the widest button, and the right sides of the buttons are all aligned with the right side of the widest button.
To solve my problem I wrote this:
int biggestWidth=buttonA.getWidth();
if(biggestWidth<buttonB.getWidth()){//if the width of button b is bigger than the width of button a
biggestWidth = buttonB.getWidth();
} if(biggestWidth<buttonC.getWidth()){
biggestWidth = buttonC.getWidth();
} if (biggestWidth<buttonD.getWidth()){
biggestWidth= buttonD.getWidth();
}
buttonA.setWidth(biggestWidth);
buttonB.setWidth(biggestWidth);//sets all the buttons to the width of the biggest one
buttonC.setWidth(biggestWidth);
buttonD.setWidth(biggestWidth);
But this is not working, because the edges of the buttons are all aligned with the edges of the first button, rather than the edges of the one with the most text. Does anyone know/think they know where I am going wrong?
Try with this layout pattern :
Thanks.