I have an application that uses localisation and in some of the languages, it is to large for the space it has, so what I'm doing is scaling it to fit, this is my code so far:
if(Build.VERSION.SDK_INT >= 11.0){
TypedValue tv = new TypedValue();
getTheme().resolveAttribute(android.R.attr.actionBarSize, tv, true);
actionBarWidth = getResources().getDimensionPixelSize(tv.resourceId);
}
View infoButton = findViewById(R.id.info_button);
int infoWidth = infoButton.getMeasuredWidth();
DisplayMetrics metrics = new DisplayMetrics();
Display Screen = getWindowManager().getDefaultDisplay();
Screen.getMetrics(metrics);
int screenWidth = metrics.widthPixels;
int titleWidth = screenWidth - infoWidth - actionBarWidth;
TextView titleText = (TextView) findViewById(R.id.title_text);
titleText.setText("hello hello hello hello hello hello");
TextPaint paint = titleText.getPaint();
Rect rect = new Rect();
String text = String.valueOf(titleText.getText());
int textLength = text.length();
paint.getTextBounds(text, 0, textLength,rect);
if(rect.width() > titleWidth){
float size = titleText.getTextSize();
float factor = activityHelper.getScreenMetrics();
float product = size*factor;
titleText.setTextSize(TypedValue.COMPLEX_UNIT_PX, product);
size = titleText.getTextSize();
}
So this makes the text massive but what I want it to do is scale the text perfectly inside the room it has, how can I set the text size depending on the room it has?
Edit:
Could I add a while loop that makes the text smaller everytime it loops checking if it fits in the space required?