Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

making fonts get larger on larger screens

I have searched Stackoverflow and google and what I find is answers for people who want fonts to remain the same size but I want them to get bigger when the screen gets bigger.

Specifically, I want very large fonts in my application. On my phone, they are 1/2 inch high - perfect. My problem is that on my 7 inch tablet they are also 1/2 inch high and I want them to scale up and be about 1 inch high. I have tried sp and dp modes and both just keep the fonts the same physical height, which is not what I want. I see there is something new for tablets with 3.2 and higher but I want to support devices from 2.3 and higher. I have seen complex code that says it auto scales fonts to fit the text in a width but that is not what I need. I want the fonts to be the equivalent of say 100sp on a phone and 200sp on the tablet. I have no graphics and simple relative layouts with very few elements on the screen. I just need to make a couple of the textsizes larger for large screens. I would think it would be simple but I can't find it.

Here is a typical text view entry

    <TextView
    android:id="@+id/textDistance"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_below="@+id/labelDistance"
    android:layout_centerHorizontal="true"
    android:text=""
    android:textAppearance="?android:attr/textAppearanceLarge"
    android:textColor="#ffffff"
    android:textSize="100sp" />

Is there a relatively simple straight forward way to do this?

like image 830
Allen Edwards Avatar asked Jul 16 '12 15:07

Allen Edwards


People also ask

Why did my font size suddenly changed?

If your windows 10 font size suddenly changed then it is most likely that you accidentally changed it by using the keyboard shortcut (ctrl + Shift + < or > or [ or ] ) to change the font size on your machine.

Why are the letters so small on my screen?

All you need to do is go to Start > type display > select Change Display Settings. Under Scale and Layout, you can change the size of text, apps , and other items.

How do I make the font bigger on my computer using the keyboard?

Keyboard shortcutHold down the Ctrl and press the + to increase the font size or - to decrease the font size. Pressing either of these keys while continuing to hold down the control key continues to increase or decrease the font until it reaches its maximum.


1 Answers

'dp' or 'dip' dimensions - specially made for been the same on different screens. So, there is not any special dimension for you task.

For implementing different text sizes you have to create several styles, and put them in folders values-xlarge, values-large, values-normal and values-small.

One style will looks like this:

<style name="BigTextStyle">
    <item name="android:textSize">50dp</item> <!-- different values in different folders  -->
</style>

And in your text view just provide style reference:

<TextView 
    style="@style/BigTextStyle"
    ...
/>
like image 175
Jin35 Avatar answered Oct 24 '22 03:10

Jin35