Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Increase the font size based on the size of the device

I planned to use different font size for the textview on different device size so as to make the letters legible. I have already decided not to use different layouts for different devices and built a common layout to fit in all the devices. Now the only problem is on the text size.

Questions :

  1. I would like to have your technical suggestions on how to alter the font size based on the size (the physical size) of the device.

  2. How to derive the font size based on the aspect ratio.

  3. Any Flaws in using this kind of approach ?

Xml for the text view

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"     android:layout_width="fill_parent"     android:layout_height="fill_parent"     android:background="#ffffff"     android:orientation="vertical">      <TextView         android:id="@+id/tvValue4"         android:layout_width="match_parent"         android:layout_height="wrap_content"         android:text="I planned to use different font size for the textview on different device size so as to make the letters legible. I have already decided not to use different layouts for different devices and built a common layout to fit in all the devices. Now the only problem is on the text size."         android:textColor="#000000"         android:textSize="15sp" />  </LinearLayout> 

Thanks in advance

like image 200
iappmaker Avatar asked Mar 30 '13 05:03

iappmaker


People also ask

How do I change the font size based on screen resolution?

Select 'Display'. Select the 'Change display settings' link towards the top of the window on the left-hand side. In the 'Resolution' section, select the pull-down bar, and a slider bar should appear. Move the slider bar down to make the text larger, or move it up to make the text smaller.

How do I automatically adjust font size in HTML?

Syntax: font-size-adjust: number|none|initial|inherit; Below are the examples that illustrates the use of font-size-adjust property.

How do I increase the font size using my 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

Yes, this approach is flawed. Android devices have different sizes, but they can also have very different densities as well.

enter image description here

You should just be following the Android design best practices.

enter image description here

They're actually very well thought out. Why would you want to reinvent the wheel?

like image 86
Stephan Branczyk Avatar answered Sep 25 '22 19:09

Stephan Branczyk