I have a design guide of 1080 * 1920.
There are several texts on the guide which should be shown as textViews.
On this case, how should I define the textSize of each texts?
If a text's height is 40px, it would be 13.3dp in xxhdpi.
But, when I make the textSize as 13.3dp, it looks rather smaller.
When trying to show numbers or english characters, it becomes even smaller.
What tactics should I need to make the view as similar as the design guide?
Related
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
I have a 32dp * 32dp TextView and a single "A" character in center with size of 10pt. In my device "A" is exactly fit to bounds (from top and bottom and looks good) but in other devices it is smaller or overflows the bounds.
Does dp, ds, px or other units help? (please remind I am not searching for this automatic resizeable font where I have exact height of 32dp)
Use sp as the unit of measurement to set text size to support different densities across devices.
Also, read this for a good explanation of dp/sp.
I occured a problem when using RadioButton. The RadioButton's layout_height must be 15dp, and the offical design guide says that 1sp is 1dp, so I set the font size to 1sp, but the TextView's layout_height is a little bigger than 15dp. It seems that when the font size is 15sp, the layout_height of the TextView is 18dp. So what's the relationship between the font size and the layout_height?
First thing I wanted to mention is the font-padding, which is by default included into the TextView size. So to make TextView's size closer to the size of the text itself - specify android:includeFontPadding="false"
Now, if you compare View with layout_height equals to 20 sp and TextView with TextSize 20sp - they are going to be almost equally high.
(There's small difference, as text might contain very high letter like "Å" or the letter like "y" which goes below the baseline)
About sp vs dp.
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.
It depends on how big is your font (Settings->Accessibility->Enable/Disable Large Text). You can change it and see the effect.
Hope, it helps.
In our company, design team expect EXACT gap (in pixel) between a TextView and the picture under/above/at the left of the TextView. For example, for a TextView and a picture under it, the gap is calculated from the text's baseline (the bottom of character H) to the top of the picture, for example, 48 dp. In my XML layout file, I use exactly the same value 48 dp for TextView's layout_marginBottom. But, after built, design team capture a screenshot and measure the gap using photoshop, and proved that the gap is not exactly 48 dp, it's actually around 50 dp. I tried includingFontPadding, but also does not work as expect. So, how to specify EXACT gap around text?
Resolution in Photoshop is set in pixels per inch where as the official Google documentation says Android will require images set in dpi.While ppi and dpi and not equivalent.Android documentation describes the relation as px = dp*dpi/160.
Supporting Multiple Screens. and
Dashboards
so you need your own calculation . you can take a look hear convert ppi into dpi
I have a basic linear layout, with image view that display photos, textviews that show text etc...and when I test my whole app on my android 2, there is never any part of the screen that doesn't show. But when I test it in the QVGA emulator, half the view is off the screen. Now, some of my text is defined to a certain size.
I never use px (only dip) in any of my xml. I use fill_parent, wrap_content where it is needed and never fix a height or length. Could it be with my text, I use say, textSize = 22dip? I couldn't find documentation on why that would not work in all sizes.
Could it be that some apps need to be programmed to those screen sizes? Or am I missing something?
Thanks!
DIP actually doesn't help in fluid layout design. DIP tries to make sure things will looks the same size across different screen density. (imagine the concept of Point in typography)
Without your code and/or screenshot of what happen, it is hard to judge what happens to your program, but 22dip text size is possibly one of the reason which:
22dip text in HDPI will become: 22 * 240 / 160 = 33 pixel
22dip text in LDPI will become: 22 * 120 / 160 = 16.5 pixel
If your setting on QVGA is HDPI, then it is actually 33 pixel tall for a letter, which consumes more than 1/10 of the screen height.
By the way, your 16:9 wide screen (vertical) may fit everything in one screen without scroll, while QVGA is only 3:2 screen, even though everything is in proportion, something would be hidden away for sure.