Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

change textSize with different language locale

I have added spanish and french to my app but some of the wording is longer in spanish then english. how can i change the textsize when the values-es/string.xml file is accessed

like image 674
Kevin M Avatar asked Jan 07 '12 01:01

Kevin M


People also ask

What is the difference between language settings and locale settings?

Language settings control in what language text appears independently of the locale settings. Often developers will use the locale to set both regional and languages settings.

How do I change the system locale in Windows 10?

Click on Change system locale… under the Language for non-Unicode programs section. Open the dropdown menu located directly under Current system locale: and click on the language you want to set as your system locale to select it. Click on OK. Click on Apply and then on OK in the Region and Language dialog.

What is the difference between thread locale and system locale?

They are independent of your language. Setting a thread’s locale or changing your system locale will change how numbers, dates, and times are displayed for controls created on that thread or running on your system, respectively. A language, on the other hand, is what we speak, read, and write.

How do I change the language of the text worksheet function?

Click on OK. If you are using the TEXT worksheet function because it is part of a larger formula, then you can instruct the function itself to use a different language for its output. You do this by including a language code (formally called an LCID) within brackets, in this manner:


1 Answers

You can use the dimens.xml resource file for this purpose. In your case you'll probably want to create a file called res/values-es/dimens.xml, and possibly also a -fr version. You can specifify the default values in res/values/dimens.xml (or res/values-en/dimens.xml, if you want to be more specific).

Example grabbed from the More Resource Types section on developer.android.com:

dimens.xml

<?xml version="1.0" encoding="utf-8"?>
<resources>
    <dimen name="textview_height">25dp</dimen>
    <dimen name="textview_width">150dp</dimen>
    <dimen name="ball_radius">30dp</dimen>
    <dimen name="font_size">16sp</dimen>
</resources> 

Apply in xml

<TextView
    android:layout_height="@dimen/textview_height"
    android:layout_width="@dimen/textview_width"
    android:textSize="@dimen/font_size"/>

Or in code

float fontSize = getResources().getDimension(R.dimen.font_size);

There are also solutions here on SO that use a iterative/recursive process to shrink the text size of a TextView to 'fit' in its bounding box (using a custom view), but I'd say above is a more robust approach, especially if you're considering adding more languages in the future.

like image 126
MH. Avatar answered Oct 10 '22 21:10

MH.