Android. Too small text in TextView - java

I follow the Android guideline and set text dimensions in "sp" units. In one of my layouts used for a ListView row all TextView sizes set to 8sp or 12sp. I tested the app in emulator with all possible screen dimensions and things went well. But some users (with Galaxy Ace and ZTE Blade) say that text in that ListView is too small (a couple of pixels per char).
Why does it happen?

read this post What is the difference between "px", "dp", "dip" and "sp" on Android?
personally use "dp" unit; is more consistent

Basically you're letting the user select the font size when using SP. This is not a bad thing per sé, but it can lead to unexpected results when devices reports small sizes to the API (either because of user actually selecting a small text size, or a bug in the device software).
If possible, try increasing the units font size to find out what font size the user is using on his device. My guess is that it is set to be very small. If you don't have access to the devices I would stick with using DP.

Related

How Can I change according to the size of the device

I want change according to the size of the device so I want make responsive app . How Can I? How Can I support multiple device size?
How it looks on Nexus S 4.7":
How it looks on Pixel:
Use dp whenever specifying sizes other than TextSizes
Use sp while specifying text sizes
Use RelativeLayout in your xml so it will adjust according to the screen sizes
Use SP whenever you want to make text user dependent
That means if user has set large text size in his/her device then all texts in all app's whos dimensions are in sp automatically change in large text. Therefore it is recommended to you sp in text size
Whereas dp is fix and no user settings are apply on dp therefore it is recommended to you dp dimensions with elements you to fix like margins and paddings
For your problem providing 'dp' should work perfectly but if it is not working they you might have some other problem therefore try to provide more details about your project
For more details read this:-
https://developer.android.com/training/multiscreen/screendensities
Use ConstraintLayout
Use match_parent and wrap_content instead of fixed values for views.
Use dp and sp instead of fixed units for the size of the views and the size of the text respectively.
Create multiple layouts according to the different sizes of the screens.
You can get more details about it on the official documentation.
By the way, to create multiple layouts for a particular layout, go to the design tab of the layout. Click on the Orientation for Preview icon in the toolbar. From the drop-down list that has appeared, select Create Other.... Now a dialog might have appeared. Do not change anything except on the left side of the dialog, there will be an Available qualifiers section. Select Smallest screen width or Smallest width (according to the options available). Click the >> symbol and enter the minimum width of the screen you want to design the layout for. For example, you enter "600dp", then the layout created will be for devices with 600 or more width (dp) as their screen width. Click Ok and a new layout will be created for a different set of screen sizes.

i need font sizes in app not to get effected by changing Settings Font size

I have my app running well as per design when the font size is at "Normal" on Settings->Display->FontSize.
When i change the font size to Small/Large entire content is mashed up. My app is content intensive and this is badly effecting the app.
From the Android developer training on supporting different screen densities:
The sp unit is the same size as dp, by default, but it resizes based on the user's preferred text size.
In other words, when the user's font preference is "Normal", dp and sp units are identical. It is only when the user changes the font preference that the sp units start to scale up or down.
That means that if everything looks good in your app now when the font preference is "Normal", you can just change all of your sp units to dp units. This will cause no change to your app when the font preference is "Normal", and will additionally make sure that nothing changes when the font preference is anything else.
Despite this is not encouraged, you can use dp instead of sp for your text size specifications.
use dp instead of sp, here is why:
android devices have multiple screen sizes and the same device can rotate screen; for you your app to look the same on multiple devices the responsive design concept came to existence, which mean widget and text size should adapt to the new screen parameters. So dp is not responsive and will look the same no matter what the screen size is, while sp is somewhat more responsive and takes into the account user preferences settings for accessibility sake.

TextView height according to the screen size

I need to place TextView at the Top of the screen.
In different situations its height is different.
I want to make TextView scrollable if it spaces more than 40% of the screen.
Of course if it has 3 words only it must space only a row.
Any idea?
You can use SDP - a scalable size unit
An android SDK that provides a new size unit - sdp (scalable dp). This size unit scales with the screen size. It can help Android developers with supporting multiple screens.
For Texts Use SSP - a scalable size unit for texts
An android SDK that provides a new size unit - ssp (scalable sp). This size unit scales with the screen size based on the sp size unit (for texts). It can help Android developers with supporting multiple screens.
Try any of these. I think these will help you alot
Give android:layout_weight="1" in xml
and use textSize in sp not dp
Use dimen file for setting text size & give padding

Better to use include images or fonts in android?

I am relatively new to android programming and was wondering if would it be better to add an image that uses a custom font, or just add the custom font and set it as the typeface of a textview? In terms of memory footprint and performance. Thanks
Using a .ttf file for Font is always better than to have images for texts because:
Less intensive on memory
Easy to scale text across various screen sizes, using desity independent text size units : sp
It's always better to use TextView. You can be certain that no matter what's yout device is if you use a TextView your app will never have all kinds of blur, visible pixels or all other stuff that you can't avoid with small images. Also you have to take care of memory. I know that it's probably small image, but when you've got a lot of them there has to be some kind of memory protection - and that is another work to do.
It's hard to find correct font size - sometimes it's all depend on your device. But that's why you have all this possibilities with different values folders. You can read more about it here: http://developer.android.com/guide/topics/resources/providing-resources.html
Another thing is, you don't always have to put your custom font manually in every TextView.
Just extend TextView class and use like normal Android component. You can see how to do it here:
http://www.techrepublic.com/article/pro-tip-extend-androids-textview-to-use-custom-fonts/

Text appearing Small in High Resolution Android Phones

I created a sample app in android. I tested it with HTC and everythig looks fine . But later when I run the program on Higher Resolution phone the test appears smaller.
How can I make the text appear same size even if the resolution changes in android?
Thanks
Make sure you're specifying the text size in dp (density-independent pixels) or sp (scaled pixels based on preferred font size), not px (pixels).

Categories

Resources