If I have a text in a button that has match_parent, is it possible to make the textSize as big as possible without cropping the text? Preferably in XML and with a maximum setting so it doesn't become too big. In other words I'd like it to make it just fit if it would split a long word, otherwise stick to the preset size.
This way, but it does not look clearly in my opinion you should to try to change your design to avoid this requirement
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.
I'm developing android application using Titanium 3.X. I need to add an image and a label (name) in a way that label is next to the image in same row and both should be right aligned. The problem is label text which represent a name is dynamic. So I can't set right property for the image view. I need to do this in a way which compatible with different devices (Screen sizes). I have given my font size as 11dp.
right property for image can be calculated by some algorithm which accepts font size, device screen width etc. But I couldn't identify it. Can anyone suggest me a way to resolve this ?
In this situation, I would add a view to wrap the image and label. I would set the view's layout to horizontal. I would then right align the view.
You should use a layout that will do the computations for you.
The RelativeLayout is quite useful in such situations. When you construction it in XML there are attributes like alignParentRight or layout_toRightOf that should prove useful. Don't forget to set the width of the TextView as wrap_content.
Is it possible to set TextView's text size to be the same as TextView height, when TextView height isn't predefined(WRAP_CONTENT or FILL_PARENT)?
solution : Auto Scale TextView Text to Fit within Bounds
i also wanted to do something like this and the closest you can seem to get is to say android:textSize=20dp (or whatever size you think is appropriate) for either your style or each element that is displaying text. since dp is device independent pixels, if it appears to be taking up the whole screen on your device, then it is supposed to appear that way on all other devices too. you might want to check on this as you might have to choose a different dp value for each of the different size/density combinations possible (depending on what kind of devices you are aimed at, also whether you are allowing the use to change the orientation) this has all that info.
I've found the library that do exactly what I want : SizeAdjustingTextView
I am trying to make a sign (the ones that drivers use at the airport to find someone "Mr Smith") and I wanted the sign to have the largest Font size possible, (its for a tablet), I could write a function to change the size depending on the length of the Text but is there a way of doing natively/better?
Thanks
The most flexible way is to create a custom view that draws the text in onDraw(). When drawing the text (with one of Canvas.drawText()) you will have to provide a Paint, and that would let you know the precise length of text, not just length of string (see Paint.measureText()).
This way you would have plenty of ways to calculate and redistribute the space (and it would totally rely on you how).
One way I can think of is calculating the length for a huge font size and then using the h/w ratio to see if I want to fill the screen in width or height.
I have TextView with height and width as fill parent. Is it possible to find out how many characters can this layout hold?
Do you mean how many characters can be entered into the textview and still be fully visible without scrolling? For proportional fonts, that will depend on the specific characters typed, including where the line break opportunities are. I don't think there's a simple way to compute that.