0

In my application i am displaying a CardView which has textview (account title). The card view height i am calculating based on device width.

Since i am setting the cardview height based on device width, i want to change the font size of textview (account title) to make font size consist based on card height.

How to we apply font sizes for textview based on device width and height?

Phantômaxx
  • 37,901
  • 21
  • 84
  • 115
Ashok Reddy Narra
  • 577
  • 10
  • 27

2 Answers2

0

In your project resources create different values directories and call it for example values-h600p and put on it the dimensions resources that you will use on your styles or layouts for screens with height >= 600dp. That's the standard way to do it. Better explained here :

https://developer.android.com/training/multiscreen/screensizes

from56
  • 3,976
  • 2
  • 13
  • 23
0

Setting font size based on device dimensions is probably bad UX. You shouldn't prioritize "look" over user experience. You risk having a situation where the text is not legible but your UI looks "good"; users won't like that. Instead, consider redesigning your CardView so that your UI still looks good even when the text in question is too lengthy. Also font size is a delicate thing when it comes to UX and so you should try staying with a standard TextAppearence style. Even in situations where you may have different layout for different screen sizes, you normally do not change font size (https://developer.android.com/guide/topics/ui/look-and-feel/themes)

Additional advice:

You should take a look at the Google News app. Benchmarking other apps that do what you want to accomplish is usual good policy.

Isai Damier
  • 976
  • 6
  • 8