Поскольку RadioButton , наследуется от TextView , вы можете использовать myRadioButton.setHeight(int pixels)
и .setWidth(int pixels)
, чтобы задать размер всей области кнопки, но не текста и не круга выбора , Чтобы изменить размер содержимого, но не общую область, вы можете использовать .setScaleX(float scale)
и .setScaleY()
, вы измените текст и область выбора, но не область кнопки.
Таким образом, чтобы изменить как область кнопки, так и размер ее содержимого:
int desiredWidth = 500; // Set to your desired width.
int currentWidth = radioButton.getWidth();
radioButton.setScaleX(desiredWidth / currentWidth);
radioButton.setWidth(desiredWidth);
И для высоты.
Если вы хотите сохранить соотношение сторон, установите желаемую ширину, а затем:
desired_height = desired_width * current_height / current_width
Как это:
int desiredWidth = 500;
int currentHeight = radioButton.getHeight();
int currentWidth = radioButton.getWidth();
int desiredHeight = desiredWidth * currentHeight / currentWidth;
radioButton.setScaleY(desiredHeight / currentHeight);
radioButton.setHeight(desiredHeight);
radioButton.setScaleX(desiredWidth / currentWidth);
radioButton.setWidth(desiredWidth);
Похоже, что шкала регулируется от центра, без регулировки положения, поэтому вам, возможно, придется изменить положение (возможно, это будет спорным, если вы используете ConstraintLayout - с LinearLayout мои кнопки стекают с экрана, когда Я изменил их размер таким образом).