Android Text Size support multiple screens - android

Is it best practice to vary your text size based on screen size or based on screen density, or both?
I already know to use sp. I have static title text that fits on one line in some screens, and wraps around to the next line on others. I need to avoid the word wrap.

Its good practice to do so. On an 10" Tablet you are better using bigger Text sizes.
You can for example define your Custom values for each type of device using the values-sw720dp
folder an place it there:
<dimen name="HeadlineSize">28sp</dimen>
Also the already System Values like android:style/TextAppearance.Large scale. Means on an Phone will this be smaller(eg. 18sp) than on an Tablet (24dp)

Related

Text sizes, different density devices and material design

I'm trying my best to follow the material design guidelines when it comes to fonts as I can, but I'm struggling to fix an issue I'm having without using dimens dependant on density. My issue is;
I'm using styles for my fonts so an example of this;
<style name="Text.MyApp.Heading3" parent="TextAppearance.MaterialComponents.Headline3">
<item name="android:fontFamily">?attr/RegularFont</item>
<item name="fontFamily">?attr/RegularFont</item>
<item name="android:textSize">?attr/TextSizeHeadingThree</item>
</style>
And applying this as the style of the text, my font size comes from the material guidelines so for Heading 4 I have
<dimen name="text_size_heading_three">48sp</dimen>
My problem is, I've got a view where there's two numbers using Heading3 in a row on the screen, This may look like +£100.00 | -£200.00, these are constrained to a separator view in the middle.
Where my issue lies is on a Pixel 4 XL (xx-hdpi) this looks fine, but bringing this down onto a Nexus S (hdpi) the text squashes together, overlaps the separator in the centre and comes off the end of the screen slightly.
It was to my understanding of the use of SP is that it would scale this text size which doesn't appear to be happening, a worry also arises that SP takes from the users text size preferences so increasing the text size of the device will likely also break this.
Just short of changing the font size for hdpi to a smaller text size for this text view, is there a way I can make this style scale with the screen?
sp actually scales in regard to the screen pixel density and the selected font size of the system.
The issue you are facing is related to the screen's actual width instead.
To achieve what you want, you can try either of the following two:
Have different sp values for your dimen for each screen width. You can do this by creating additional resource files that would contain your dimen values and will be screen width dependant. You can read more about this here:
https://developer.android.com/training/multiscreen/screensizes#TaskUseSWQuali
Use an autosizing TextView. You can find more information here:
https://developer.android.com/guide/topics/ui/look-and-feel/autosizing-textview
sp units are literally about the user's choice of text size:
Scale-independent Pixels - This is like the dp unit, but it is also scaled by the user's font size preference. It is recommend you use this unit when specifying font sizes, so they will be adjusted for both the screen density and the user's preference.
Basically users can choose the general size of text on their device, and that multiplies dp values by a specific factor (Normal is * 1.0, I think Huge is * 2.0) and that's what the sp value is. When you specify sizes in sp, you're allowing the system to scale that text up so it's readable for everyone.
So you need to be mindful of that when designing - it's always worth having an emulator with a small screen (limited space) and the text size set to the largest setting, just to make sure everything still fits in those extreme cases.
You have four options I think:
reduce your font's sp size in the layout, so it always fits
make different layouts for different configs, and tweak that (more work for you)
use autosizing TextViews like #kandrit mentions - set the space you want to fill, and it will scale the text size to fit it (this sounds like what you were expecting, and you can tweak things like having a fixed set of possible sizes)
don't use sp, use dp instead (won't scale according to the user's preference - but above a certain size, it doesn't need to because it will be readable)
You'll get a warning about the last one, but in my opinion it's completely fine and the right thing to do in some cases. Think about an app with a clock in the middle of the screen - it's a fixed size, designed and laid out a certain way, and it's large enough to be easily read. It's meant to look a specific way, take up a specific area of the screen, and there's no need for it to change size - so it makes sense to define it in dp like any other visual element. Maybe that works for what you're doing!
Problem is not with your text size, it is with your layout design
I also had the similar problem I solved it by giving a margin to views which was placed inside constraint layout so in a case of large screen it will use constraints and ignore the value of margin and in case of small screen it use the value of margin to keep views separate
If you are using a Linear Layout then set layout_weight to 1 and give margins to views then it will work same as with constraint layout

android is it standard to make buttons text and other views text larger in tablet size?

Is it standard to make buttons text and other views text larger in tablet size? I make dimens.xml for different device sizes and make different text sizes for different device sizes. for examle in normal dimens file:
<dimen name="small_text_mobile">14dp</dimen>
and for large size dimens file:
<dimen name="small_text_mobile">18dp</dimen>
and use this dimens for my textViews and buttons , extra..I want to know if it is standard? or no need for that and texts of views like buttons should be in same size in different device sizes?
The unit used (dp) will convert the button and layout sizes to appropriate pixel sizes on the actual device (making them independent of actual device screen size). Therefore, on a small device it will look relatively similar to a large device. However, depending on the situation, it may be more efficient use of screen space to have different dimensions/layouts for different screen sizes. It really depends on the view being used and the level of user experience required for it. A lot of the time dp will get the job done close to what you would want. The Android documentation on supporting multiple screen sizes is excellent in explaining all the different situations and control a developer could have on their layouts.
Depending on the layout, it may be better practice to create multiple layouts to fit small and large screens in different orientations. It depends on the layout and how complex it is. If it looks unnatural on a certain device, I would recommend creating another layout (or applying some changes on the current one) to better fit all devices.

Android Design Screen for different screen size

app screen on galaxy s4 it skip right and bottom part because of small size mobile
I am having problem in Design different screen size.
how should all 5 categories will support most of the mobile screen?
my Android App Design Normal screen works on 5 inch mobile screen where as for 4 inch screen it skip below content.
for example it work nice on samsang galaxy s4 (5 inch) also on nexus 4.
but as shown in image when i see on nexus S(4 inch screen) it skip some bottom and right part .it cannot hold full layout mostly top and left part it display.
how to design normal screen which support these screen size changes?
is it compulsory to use wrap_content or Match_parent or fill_parent only to get rid of it.
for that also i am confused of specifying image size for different screen size in drawable.
also is normal screen be of different density such as hdpi,mdpi,ldpi etc.
how to solve this issue is it sufficient to use dp and sp?
and last one, in Android Studio we design 5 types of layout.for example activity_channel_list.xml(small). etc( for normal,large,xLarge).what last just activity_channel_list.xml represent.is it like if not any layout is selected.this will be selected by default.
Thanks in advance.
If you want to design layouts for different screens then make folders accordingly link
layout-mdpi
layout-hdpi
layout-xhdpi
layout-xxhdpi
If you don't want create different layout for different screens then simply use dimension file and create different dimens in that like
values-hdpi (dimen)
values-xhdpi (dimen)
values-xxhdpi (dimen)
and the difference between dp and sp is, we use dp for give dimensions to the image, and for size purpose and sp is use for define text size
the screen size id efferent and you cant make a layout for every one you need to try categorize the screen with layout selector
if you use sp for text the text size will change when user change the android font size and it is better to use dp for text
and last Question is like first one you need to categorize layout for size and density normaly
How should all 5 categories will support most of the mobile screen?
Take care if these following aspects while designing layouts:
1.Always design layouts inside scrollview, so that for smaller screens user will be able to view complete layout by scrolling
2.Use sp for text Sizes
3.Use dip(density independent pixels) for all widget sizes, usage of dip makes the size of widget according to mobile profile(like 240*320 may use ldpi so according widget size will change)
4.All the icons you are using you need to generate for all profiles(ldpi,hdpi,xxhdpi,xhdpi) and store in drawable-xxxx folder
If you dont want to generate images for all profiles you can use font icons (like font awesome,iconmoon)
font icons appear according to screen sizes.
5.Last but not least, avoid using hardcoded margins between widgets use attributes like gravity,center_in_parent etc.. so that screen looks uniform in all devices.

Different Text Sizes for different Screen Sizes, using what ratio factor?

Hello I am using different textsizes depending on different screen sizes.
Like:
values-small: dimens.xml -> ?
values-normal: dimens.xml -> 10sp
values-large: dimens.xml -> ?
values-xlarge: dimens.xml -> ?
I want to know if there is a formula to set the right sizes depending on small, large, xlarge instead of setting sp size by testing it on different screens^^?
second question: is values-normal neccessary, isnt "values" folder == values-normal?
third question: what happens when I declare dimens.xml for small, normal, and large and the device is a XLARGE device will it use dimens.xml from values? or valuse-normal? or the next smaller one values-large?
thank you
I want to know if there is a formula to set the right sizes depending on small, large, xlarge instead of setting sp size by testing it on different screens
Not really. Many apps do not change their font size at all based on screen size, just as most Web apps do not change their font size based on browser window size. Of course, you are certainly welcome to specify different <dimen> resources for different screen sizes, including dimensions for use with text. And there's nothing stopping you from using an algorithm like the others suggest; just understand that there's no real reason to use that algorithm. To put it another way, a graphic designer should be telling you how big to make the text, not a calculator.
Moreover, the -small, -normal, etc. buckets are not used as much anymore, in favor of the more flexible -wNNNdp, -hNNNdp, and -swNNNdp buckets.
isnt "values" folder == values-normal?
No.
Suppose you have res/values-small/, res/values/, res/values-large/, and res/values-xlarge/. Further suppose that each resource set defines a text_size dimension resource, and you use that in in layouts (e.g., #dimen/text_size).
A -normal device will then pull from res/values-small/, as -small is for small screens or larger. Your res/values/ version of the resource will never be used. Hence, the typical pattern would be not have res/values-small/, putting your -small resources in res/values/, and overriding that default value in res/values-normal/, res/values-large/, and res/values-xlarge/.
what happens when I declare dimens.xml for small, normal, and large and the device is a XLARGE device will it use dimens.xml from values? or valuse-normal? or the next smaller one values-large?
It should pull from res/values-large/, as that is the closest match among the qualifying resource sets.
This is the common problem in majority of Android projects to support varied screen sizes.
In short, you can make use of scalable DP and scalable Font approach.
Android project structure inherently allows specifying different font size (SP) and margin values (DP) by defining them in dimens.xml files for supported screen sizes. But the problem that still remain is - what values to be used ? UX designers normally provide style guides for only one set (e.g. 360x640 DP screen size) and don't provide for all other supported screen sizes. So the problem to use right vlaues for other supported screen sizes still remain unanswered.
One good solution (per my understading) is to use readymade scalable dictionary of dimens.xml files, something similar to the dictionary of files provided by this library. After adding these xml files to project, you just need to use the keys in your layouts, then Android automatically uses font/margin value from respective directory. Please refer here for visual difference - with and without this approach.
I use the ratio 0.75 : 1 : 1.5 : 2 same as for DPIs. It works fine.

trouble with font size for different screen size/resolution

I know this has been answered in other questions, but nothing is working for me. I have a text view where I want the text to appear the same size in a variety of density/screen size combinations. I have tried specifying
android:textSize="30dp"
and
android:textSize="30sp"
and have also used
TextView text = (TextView) findViewById(R.id.text);
text.setTextSize(30 * (getResources().getDisplayMetrics().density));
30 is my font size *****
the text doesn't scale properly. It becomes way too small at lower densities and as screen size increases. Are there additional techniques I can use to scale my font?
create layout-large, layout-small, layout-xlarge etc.. versions of your layout xml file.
You can set the size differently in each so that the font will look right across a variety of screen sizes.
After years of constantly having everything slightly off on different devices, I recently discovered that the inches and cm measurements for dimensions are literally that.
So even on devices where 160dp isn't quite an inch, specifying 1inch will give exactly that, on everything, even if they have a custom scaled ROM.
I now specify anything I want very tight control over with these.
If you just want to have separate font sizes for separate screens, you can create dimens in your value.xml for sw600dp and sw720dp folder too and put different values there. You don't need to create separate xml layout for each, if you just need to change font sizes.

Categories

Resources