I want to use SP when defining my fonts so that they scale according to my User's needs. However one screen which I have created looks great when on Normal or Smaller size but wraps text and looks messy on Large size.
So where I have text which has two label/value pairs of information going across the screen, which looked great on Normal, I need to change this to having one pair on each line so that this stops looking messy on Large.
But if I now switch back to Normal or smaller size this does not look so good and not as nicely spaced as before,
So...what I would really like to do is have two layouts, one which I use if the user has a Large+ and a different one for Normal or smaller. To get this to work I need to be able to get the User's currently selected Font Preference.
Can anyone help, I cannot find any reference to how to do this?
Related
So I have read possibly everything about the difference between sp and dp. I can say that I do understand why sp is better than dp regarding text size. One thing I don't understand and want some help with is how do I make the text look the same with every possible font size the user has selected for their phone? Is it that bad to use dp for text size? (I know that the app won't take the user's phone font size into consideration but at least it will look the same across the board.) Any advice would be appreciated.
To make the text look the same irrespective of the users' choice, use dp. To change the text size according to users' choice use sp. So, if you have a constraint that the text size should remain the same use dp.
Is not bad at all to use DP as text size. It just won't follow the users preferences regarding text size. We have to use the tools we have, to best fit our needs. I always use DP in elements wich i need to maintain the layout. If you don't want the text size to change, use DP. Some times i use textAutosizing When the text changes. And often i use sp, when dealing with "content" text, wich can grow and scroll, shrink and fit.
Is there any way to change the layout of your app based on what text size the phone is set to? I know you can set your text so it will be static (stay the same size) but I've had some users complain because the app doesn't look good because of the large text. These are mainly older people who need the large text and it would be nice if there was an easy way to accomplish this without splitting one activity into two separate ones so they could still use it. Any ideas?
First situation
Let's say I have a screen with several buttons placed in vertical order.
I distributed available space between them using weights.
So, on a large screen buttons get bigger. That's what I want.
But how I make the text look bigger to?
Okay, I took a class from here Auto-fit TextView for Android.
But is that normal that android does not have a standard approach for this and we have to use a custom class?
That's weird. How do developers deal with it?
Second situation
Let's say it's okay to use this custom class.
I have a ListView
I want the items to increase their height as the height of screen increases.
How do I do that? I found a difficult way to do that, but it all seems like lots of troubles.
How do developers usually do such things?
Or maybe developers don't resize list items at all?
Maybe it's okay if they are set in dp and look quite small on big tabs?
I'm adding this as answer because I did a lot of typing.
If you're using Eclipse, you'll see that there are a number of folders in Drawables. They are essentially for sm, md, lg, xglg, etc... All screens fit into one of those categories. What people normally do is design a layout for each. And, yes, there are hundreds of individual sizes. And yes, it's a pain to create for all of them. But many developers do exactly that. And don't forget about landscape and portrait. Need layouts for those too.
in my android application, I want to display some images of plants (i have more than 100 of them) a i also want to support different screen sizes, but my problem is i can not have images for every screen density in res/drawable folder, because size of my application horribly increase. Is there any solution how to do this? (maybe in code) Thanks a lot.
From what I understand, you want to have the text wrap around the image. You could best achieve this using this library.
As for the images, you would only need to store them at a size that looks good on the largest devices you are looking to support. For the other devices, you would just scale those down. If you're going to use the above library, you might need to set the following parameters on the ImageView in the XML file to have it scale down correctly:
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="0.5"
Note that you will need to fiddle around with these (especially the weight) so that you get the best fit for your application.
EDIT: To conform to your requirement in the comment, the best way to go would be to use a WebView. This does mean you will need to create HTML code for your articles, which would completely change the question.
What you could try is to have a LinearLayout surrounding the image and add TextView objects to it programatically. There are good chances that this will look bad depending on the amount of text you will be adding.
I have an Android app that needs some adjustment if the user sets their font size to extra large (via Settings -> Display -> Font size in 4.0 and higher).
Is there a simple way for me to tell what the user's font size preference is
Updated:
in my layout.xml I have lines similar to to setup a button
android:textAppearance="?android:attr/textAppearanceMedium"
android:textStyle="bold"
android:typeface="sans"
Notice that I'm not setting the font size directly. This layout works and looks good in all cases, except for the Extra Large setting. In that case, due to space limitations, it causes the button's text to wrap to 2 lines.
My goal is to make a slight wording change in the case of Extra Large so that it doesn't wrap
There's a FONT_SCALE parameter you should be able to query the system for. I haven't used it myself, but I imagine retrieving its value would look somewhat like this:
float fontScale = Settings.System.getFloat(context.getContentResolver(), Settings.System.FONT_SCALE)
However, I'd also like to point out that usually you shouldn't be dealing with this value directly. In stead, use sp units for textual content so that you don't have to worry about adjusting to user-preferred font sizes yourself, but rather let the system handle that.
Also refer to: Why should we use sp for font sizes in Android?