tl/dr
I am trying to change some layouts sizes in code, and I can change some of them, but the other ones that needed to update based on the changes won't update together. Instead, they retain the previous width that the changed ones had.
So, I am fooling around with Android Studio and trying to change the size of some LinearLayouts Programatically.
This is what I'm doing:
final LinearLayout ll3 = (LinearLayout)findViewById(R.id.box3);
ViewGroup.LayoutParams p3 = ll3.getLayoutParams();
int w3 = 5;
float aux = (float)w3/15;
p3.width = Math.round(max*aux);
ll3.setLayoutParams(p3);
and then this is what I'm getting:
Log.i("OnLongClick p3_width", Integer.toString(p3.width));
Log.i("OnLongClick ll3_getWidth", Integer.toString(ll3.getWidth()));
OnLongClick p3_width﹕ 179
OnLongClick ll3_getWidth﹕ 224
The ll3.getWidth() is returning the previous value, which ll3 HAD before setting the new parameters. If I repeat the process, then it will display something like:
OnLongClick p3_width﹕ 314 //New Value
OnLongClick ll3_getWidth﹕ 179 //Old (previous) Value
I need the ll3.getWidth() to be the same as p3.width, because I'm calling it in another function in order to recalculate the other LinearLayouts that my app has. Otherwise, when the app redraws it, the rectangles changed manually will change, but the other ones (which uses the changes to modify itself) will remain the way that the changed ones were previously (sorry about this sentence).
I'm thinking that this happens because the setLayoutParams must be doing its job further in time, and not before I call getWidth(), but I have no clue if that is trully the problem, and how to fix it.
Any help is apreciated.
Thanks in advance!!!
EDIT2: If I send
openOptionsMenu();
closeOptionsMenu();
It fixes the size of the rectangles. However, it presents a delay doing that, so it is reeeally ugly. Anyway, I would need to place whatever is in the middle of openOptionsMenu() to fix that (closeOptionsMenu() doesnt change the view, only closes the menu).