0
votes

My first Android App. And, am trying to get this sorted -> setting different text sizes, layout sizes for different screen / device sizes. Now, I Googl'ed a lot , then read several Stackoverflow threads, & am doing this: Created different folders under 'res' like values-ldpi values-mdpi values-hdpi values-xhdpi values-xxhdpi values-xxxhdpi

Then I put a dimens.xml & styles.xml in each folder above.

Phew! But this doesn't suffice. I want to have different textsizes (and other dimensions, am not speaking about images here) for phones & different ones for tablets. I know there are these 'values-sw600dp, and 'values-sw720dp' which they say is aimed at tablets. But even within each tablet size, I need to differentiate the different densities right? For example, within 'values-sw600dp', I need to have different textsizes for, say, hdpi, xhdpi, ... How do I do this? Any help please?

Here is an example of what am doing:

    TextView textView = (TextView) findViewById(R.id.text_interference);
    textView.setHeight(layoutHt);
    textView.setWidth((layoutWd-20)/2);
    int dimensControlButtonTextSize = getResources().getInteger(R.integer.CONTROL_BUTTON_TEXT_SIZE);
    textView.setTextSize(dimensControlButtonTextSize);

Then in dimens.xml, it would be: 17

This value, i.e. 17 here, will differ in each device i.e. it is given a different value in each dimens.xml under each values- folder. I hope am clear.

1
Why are you doing anything besides images using densities? There's a reason dp exists.ianhanniballake
these folders are for dimes.xml ad styles.xml, not for images. So my question is about setting dimensions & styles, @ianhanniballakeJean
Yes, can you give examples of what dimensions and styles you are changing based on density? Those things don't usually change by density.ianhanniballake
@ianhanniballake text sizes change based on density right? for example, I have a 'settings' button. The text 'settings' in the button appears larger in devices with small densities & smaller in devices with higher densitiesJean
Text sizes are usually in sp, which automatically takes care of being the same physical size no matter what density the screen is. Again, include an example of what you are doing.ianhanniballake

1 Answers

0
votes

Drawable resources do not need to be duplicated per screen configuration, except for special cases like you have a full screen splash that would be displayed differently for landscape and portrait. Normally for icons, specifying once in the main resources folder (under hdpi, mdpi, xhdpi, xxhdpi...) should be sufficient.

I would find screen configuration specific resources to be useful for dimen values, like padding, margin, width of items, etc...