I am new to working with multiple screens and need help with the following:
I have 2 devices:
Samsung S4
Samsung Tablet:
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.
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"