问题描述:

I'm getting sick to find the best away to put the same scale for textView's in different screens density and resoution.

I tried:

  • Create different folders, for different density and put "dimensions". Example, folder values-xhdpi and dimensions.xml, values-ldpi and dimensions.xml too. On my code, programmatically i get textView.setTextSize(getResources().getDimensions(R.id.myDimension);

    In xml, 20sp

  • like example above, but put this textView.setTextSize(TypedValue.COMPLEX_UNIT_PX, getResources().getDimensions(R.id.myDimension);

  • Add textAppearence , like textView.setTextAppearance(this,android.R.style.TextAppearance_Large);

But all examples, i got what i wasnt expected, because got texts biggers in biggers density. like in image below

this happen except if i change my dimension in appropriate xml. But, what structure should i follow?

For an example, in drawbles, people reccomend to use scale like 3:4:6:8, but here i didnt follow a structre.

What are the best pratices ? What people normally do..?

What i want? this..

网友答案:

You have to use a pixel independent unit for your text size. Make dimensions with sp unit and load them programmatically.

For supporting multiple screens take a look in android documentation

For the sp unit says :

Similarly, you should prefer the sp (scale-independent pixel) to define text sizes. 
The sp scale factor depends on a user setting and the system scales the size 
the same as it does for dp.

In other words you have two

You have to declare in values file dimension elements. If you don't like the result and you want to declare for each screen category specific text size you have to do the following :

  1. You can create a values folder for each dpi. For instance , the folder name can be : values-hdpi , values-xhdpi etc.
  2. Inside the values file you can place a dimens.xml file in which you will declare as

     <resources>
        <dimen name="small_font_size"=10sp></dimen>
        <dimen name="large_font_size"=20sp></dimen>
     </resources>
    
相关阅读:
Top