androidscreens

Android dimens file for multiple screens


I am new to working with multiple screens and need help with the following:

I have 2 devices:

  1. Samsung S4

    • display class: normal
    • smallest width: 360dp
    • resolution: 1080 * 1920
    • Density class: XXHDPI
    • Density: 442dpi
  2. Samsung Tablet:

    • display class: large
    • smallest width: 600dp
    • resolution: 600 * 1024
    • Density class: MDPI
    • Density: 168dpi

My problem is that the values for both devices are getting pulled from the same dimens file.

Can you please tell me what the name of the values directory should be for each?

I have tried:

values-sw360dp-xxhdpi values-sw600dp-mdpi

However, this has not made a difference.

I have a method:

public void setTextSize(Context context, TextView view, int textSizeInSp)
{
  float spToPixel= TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_SP, textSizeInSp, context.getResources().getDisplayMetrics());

  view.setTextSize(convertSpToPixels(spToPixel, getApplicationContext()));
}

I have 2 dimens file entries:

values-sw360dp-xxhdpi\dimens

<dimen name="font_english_large">20sp</dimen>

values-sw600dp-mdpi\dimens

<dimen name="font_english_large">32sp</dimen>

I programmatically attempt to change the text size by calling:

setTextSize(this, textView, (int)getResources().getDimension(R.dimen.font_english_large);

Thank you.


Solution

  • you will need only values and values-large, then add your font sizes in the corresponding files using sp metrics. For example in values/dimens.xml add

    <dimen name="randrom_text_font_size">18sp</dimen>

    and in values-sw600dp/dimens.xml add something like

    <dimen name="randrom_text_font_size">28sp</dimen>

    Then in your java code:

    textView.setTextSize(0,getResources().getDimension(R.dimen.randrom_text_font_size));
    

    Or in XML

     android:textSize="@dimen/randrom_text_font_size"