I am new to working with multiple screens and need help with the following:
I have 2 devices:
Samsung S4
- display class: normal
- smallest width: 360dp
- resolution: 1080 * 1920
- Density class: XXHDPI
- Density: 442dpi
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.
- If I have small text, it looks OK on phone, but too small on tablet
- If I have large text, it looks OK on tablet, but too small on phone
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.
you will need only
values
andvalues-large
, then add your font sizes in the corresponding files using sp metrics. For example invalues/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:
Or in XML