I have a RadioGroup
that I'm trying to scale down because it's too big. So I use setScaleX()
and setScaleY()
and scale it down.
It works but the problem is that the View changes X and Y position when I scale it. I want it to keep the same top left coordinate after scaling. How to make the View stay put after scaling?
See code below:
CSRadioButton radiobutton = (CSRadioButton) field;
RadioGroup rg = new RadioGroup(this);
rg.setOrientation(RadioGroup.VERTICAL);
JSONArray choices = radiobutton.getChoices();
for(int j = 0; j < choices.length(); j++){
JSONObject currObj = choices.getJSONObject(j);
String text = currObj.getString("text");
RadioButton rb = new RadioButton(this);
rb.setText(text);
rg.addView(rb);
}
rscroll.addView(rg, lp);
rg.setScaleX(0.7f);
rg.setScaleY(0.7f);
The default pivot point for scaling and rotating a View
is its center. You can set the desired pivot coordinates using View.setPivotX()
and View.setPivotY()
:
rscroll.addView(rg, lp);
rg.setPivotX(0);
rg.setPivotY(0);
rg.setScaleX(0.7f);
rg.setScaleY(0.7f);
This will cause the upper left corner to stay fixed.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With