I know how to set the width and height of a view using LayoutParams by doing the following:
android.view.ViewGroup.LayoutParams params = button.getLayoutParams(); params.width = height/7; params.height = height/10; button.setLayoutParams(params);
Now, as soon as I want to apply the same height and width to another button, I need to create another LayoutParams or overwrite the existing one, like here:
android.view.ViewGroup.LayoutParams params2 = but2.getLayoutParams(); params2.width = height/7; params2.height = height/10; but2.setLayoutParams(params2);
I have about 50 buttons in my application, and I doubt that this is good code to get all Params, just to change the width and height - I want to save the remaining parameters (toLeftOf, [...]).
Is there a way ONLY to change the width and height of the parameters, but save the rest of the parameters? Therefore, it looks something like this:
android.view.ViewGroup.LayoutParams params = button.getLayoutParams(); params.width = height/7; params.height = height/10; button.setLayoutParams(params); button2.setLayoutParams(params); button3.setLayoutParams(params); butt[...]
Thank you very much in advance.
android view params
user2875404
source share