i have two buttons put in line inside layout. i d' like them to have the same width. but width of every button have to be equal the widest of them. now i use ViewTreeObserver.
class LayoutListener implements ViewTreeObserver.OnGlobalLayoutListener{
private Button btn1, btn2;
public LayoutListener(Button b1, Button b2){
btn1 = b1; btn2 = b2;
}
@Override
public void onGlobalLayout() {
int w1 = btn1.getWidth();
int w2 = btn2.getWidth();
if (w1 < w2)
btn1.setWidth(w2);
else
btn2.setWidth(w1);
}
}
but it's not good decision becase elements are redrawn after they was shown to the user and it looks terrible. and question as you can guess, how can i reach needed behavior? is there way of markup manipulating or i should implement special code? it's desirable to avoid creating custom layout that could be used as a container for buttons.