Android: Text View size and different font size - android

I have read a lot and still have not found the solution. I have an application that displays textviews, what I want to do is when I change the font sizes from the phone settings (large, small, medium) the textview size on the screen remains unchanged.
But after I tried following the sizes hpdi, xhdpi, xxhdpi... and set the textview size to "sp" then with different font sizes the textview size still gets bigger if I choose large font size.
Can anyone help me?

Actually sizes in hpdi, xhdpi, xxhdpi... folders are sizes for different phone screens and put different sizes in them is not related to have fixed font size(even phone size setting set to large).
You have to set size with dp, not sp to phone setting can not effect on text size.

Related

Android: text cropped in some devices

In my android app, there is a certain layout with a fixed height. In this layout, there are some TextView s arranged vertically. I have set the font size of text fields to be somewhat larger (18sp).
In almost all the devices I checked, The text fits inside the fixed sized layout. But in few devices, The bottom TextView gets cropped out of the layout.
If the proportion between text unit size (sp) and the layout unit height (dp) is the same in all devices, I wouldn't expect this to happen.
So, is this due to something wrong with the devices? Is there any way I can fix this?
Screen density is different than screen dimensions. dp normalizes densities across devices, but they can still have varying screen heights and widths. The obvious example is tablet vs phones, tablets have the same screen densities as phones but much larger screen dimensions. Just like that, some phones have smaller screens than others, so you need to take that into account when using fixed height layouts.
To get around this problem, you can take advantage of the width and smallest-width resource buckets and provide different layouts for smaller devices.
As it seems, the proportion between a unit sp and a unit dp depends on the font size setting (Settings->Display->Font size).
I could recreate the issue on other devices when I set the font size to be Huge.
So, it is not a good idea to set fixed sizes to layouts containing text.

How to keep Font Size constant irrespective of device font size or screen density

I have kept my EditText font size as 16sp. However when I change the device font size, the EditText font size also changes. I tried using dp instead of sp which worked but I doubt if it will work well on different screens. How to I keep font size constant using sp as the unit irrespective on device font size and screen density?
You should use dp. The only difference between dp and sp is that dp will ignore the user's text size setting for the device. The result will be that the font size measured in real-world units (points, inches, etc.) will be the same on all devices, regardless of pixel density.
Note that screen size never affects any of this. If you want the text size to be defined in terms of a certain fraction of the screen dimension (e.g., width), there's nothing built into Android's unit system to support that. You'll have to either do the calculation in code (taking into account both screen size in pixels and pixel density) or define the size using alternative resources for different screen sizes.

Android button and the size of text

I have a layout with a few buttons that takes the space of the entire layout using weight properties.
Each button has some text on it with a fixed size which is set by android:textSize="30dp" so on a screen size of a small mobile device (A phone) the text's size if about the size of the button. But on a large device (A tablet) the button size expands yet the text size remains the same (30dp).
I want the button size and text size ratio to be maintained in every resolution, can it be done using the layout XML code? I would like to avoid doing it programmatically.
The solution is very simple
You should use a dimension.xml with diferent sizes each density/size and place it on:
values-mdpi
Values-hdpi
values-xhdpi
values-large (5.1' 5.4' y nexus7 tablets/phones )
values-xlarge (bigger tablets)
You can use values-sw600dp (nexus 7) and values-sw720dp(10') too.
Ah! And use sp for text, not dp. SP put the same size for all the fonts. Text Allways with SP
Remember, you allways can create values/drawables/resources in general for a lot of separate configurations: Landscape portrati, langauge, sizes, densities, night or day, version of android .... And you can merge it!
http://developer.android.com/intl/es/guide/topics/resources/providing-resources.html#SmallestScreenWidthQualifier
text size should be mentioned in sp, not in dp try like this
android:textSize="30sp"
Size of the text. Recommended dimension type for text is "sp" for scaled-pixels.
make different xml layout file for tabs and phone and try this for button
android:textAppearance="#android:style/TextAppearance.DeviceDefault.Large"
you can fix the size of buttons by giving weight and for the text of a button you can do this to auto size them:
android:autoSizeTextType="uniform"
android:autoSizeMaxTextSize="24sp"
android:autoSizeMinTextSize="20sp"
Set the min and max size what you need and put these codes inside a button body:)

Best way to set text size?

What is the best way to set the text size so it looks the same on all devices? The biggest problem I am having is setting the text size on the buttons so everything fits or isn't too small. I have tried setting the size in the xml, and I have just tried setting it dynamically by getting the screen size and messing with the screen width and height to set the size. I had tested different things on different devices and thought all was well, until I just tried my app on the Galaxy Nexus and half of my words were getting chopped off inside of the button. I made some adjustments and the font is now way too small on tablets.
Using the xml has worked fine for me before, but most of these new 7" tablets use the large layout, so my images and text are really small if I set the height, width, and text size with the xml. Setting the widths and hights dynamically have helped with the buttons and image sizes, but the font still doesn't look quite right.
Is my best bet just to find a happy medium via xml(large, x-large, etc.) or are there other ways?
Have you seen this article: Supporting Multiple Screens ?
It says:
you should prefer the sp (scale-independent pixel) to define text
sizes. The sp scale factor depends on a user setting and the system
scales the size the same as it does for dp.
The same issue is explained here, Different text size for different hardware

TextView in android

I am developing an application in which the layout is independent of screen resolution.
Now my problem is that in TextView the textview layout does change itself when the resolution of screen changes but the size of text remain same.
I want that when the resolution is high, according to that the text size should also adjust itself(i.e. text size should be changed).
And simillarly when resolution is low the text size sholud also shrink.
But here when i reduce Y-AXIS to an extent the text vanishes.
I will really appriciate any answer.
Thank you.
You should be using sp for your android:textSize.
Make a values folder for each of the four densities and make a common dimension value for each density.
So at low density it is a certain value, medium density it is a certain value and so on.

Categories

Resources