Android - displaying fractions using unicode - android

I am trying to make a fraction:
I am using this is a text view but it is not rendering very nicely:
"5"+'\u2044'+"9";
It does not turn the text into a nice fraction instead it sort of covers part of the numbers and squishes them together.
Any solutions or alternatives?

Try:
tv.setText(Html.fromHtml("<sup>5</sup>/<sub>9</sub>"));
Don't know if that will look good, but it's worth a shot. Otherwise, other than the single-glyph fractions like 1/2, I suspect you either will need to go without or render it yourself.

Related

Changing text's size according to TextView

Hi guys I've wondered if I could resize the TextView's text in order to make it fit withing the text view.
I want the text view to have a default text size, but in case the text is too long and requires more text than the TextView could offer, the text size should get smaller.
I've seen this answer which is awesome, but it's also from 2013, so I've wondered if there's a simpler way of doing this. Android keeps changing and evolving so I just wanted to make sure there's no easier solution first.
You can use AutoFitTextView for better result .
A TextView that automatically fit its font and line count based on its
available size and content.
There is no built-in way of achieving this in Android, so you'll have to resort to 3rd party classes and libraries to fix your problem (Like the one you linked)
I have tried a few different classes i found from googling around about 6 months ago, but i never found a 100% working solution, there were always some little kinks or flaws in my experience.

Letter Spacing in EditText for Android

I am trying to have a custom EditText based on the background that i am using for. The Background image has some spaces between the entry areas so i need to have some space between the characters(kerning) to fit them right in. So for example after every character the user enters, i need to put 4 whitespace after that.
I couldn't find any solution for this on the net so far, some people suggested TextWatcher, but i couldn't manage to make it work as i want it too.
Can someone help me about it?
Thanks
I have you considered using a custom font? Some font types are made to stretch out or shrink or have empty spaces. With so many different fonts available online, you can definitely find something. You can also make your own with a software. It might be time consuming if you start the lettering from scratch. I'm not 100% sure if it'll fit exactly to your background, but it's idea that you can consider.
If it doesn't fit, I supposed you can always customized the background to fix your font too. Here's the code for those who might want to use custom fonts in their app too.
Typeface myfont = Typeface.createFromAsset(getAssets(),
"fonts/Blocks2.ttf");
myeditText.setTypeface(myfont);
The font is in the asset folder under another folder called fonts.
This question is related to How to change letter spacing in a Textview?
As shown at this issue: android format edittext to display spaces after every 4 characters a solution might be to insert spaces with Java code...
You need to use TextWatcher to achieve visual purpose spaces.
And use any simply split string by space logic to join it back or loop
through the entire string per character wise and eliminate (char) 32
from the string
As far as i know actual character spacing is not possible, though i'd love to use that myself as well.
Another option might be to use a custom font with the character spacing included.

Android Text Display - Canvas.drawText() output pixelated

My Android app displays text in a few different ways, and there are some annoying differences between them I was hoping folks could help with.
When I use display methods that might be termed "automatic," the text is displayed very nicely. By automatic methods, I'm referring tools, like Toasts and Button widgets where I just have supply the text, and the OS (or "environment" or whatever) displays it for me. The letters are nicely curved, pleasant to look at, and easily legible.
However, in my code where I handle the text display (using Canvas.drawText() in a Surface Runner View), the text quality is poor. The text is still legible, but it looks pixelated. The letters just don't look their best.
I've tried experimenting with Paint.setTypeface(), using Typeface.SANS_SERIF for example, but the quality of the display when it's my code is always poor. Doable, but poor.
Has anybody else experienced this? By any chance does anybody have a solution?
You might also try playing around with Paint.setAntiAlias(boolean) or Paint.setSubpixelText(boolean).

Why does margin override marginLeft in Android (same with radius, etc)?

This makes no sense to me, coming from CSS. In CSS, if you specify a margin and then margin-left, the left margin will assume the more granular value.
In Android, it is the opposite. Same goes for android:radius, and I'm sure other values.
My question is: why?.. It makes no sense. Is there a single reason for doing it this way?
Edit: prompted by trying to find a solution to yet another Google ADT/Android bug http://code.google.com/p/android/issues/detail?id=7588
I have had the same frustration, but if you think about it, which value should be used? I know in your post you say that CSS uses the "more granular value" but it all boils down to pixels in the end and the result is simply two pixel values that need to be chosen between. The CSS standard chose to do it one way, Android chose the other, I don't think either approach is wrong, they are just different.

Android TextView and how to determine the number of visible characters

How can I determine the number of visible characters that a TextView can display. For example if I change the orientation this number may change. If I change the resolution then also the number of visible characters changes.
Thanks in advance
Thank you for your answer.
Currently I am developing a small text based game to become acquainted with the Android API. For that reason I need to know exactly how much characters can be displayed in the visible area of a TextView widget. I saw an example of Paint but wanted to know if there are better solutions.
Ideally, you design your GUI such that it does not matter. For example, you can use android:ellipsize to deal with strings that are too long for the available space.
There are classes in the 2D drawing APIs (e.g., Paint) that seem to be tied into this, but it does not look like much fun.
You can use ellipsize property but there has been a bug that has been filed on the same
http://code.google.com/p/android/issues/detail?id=2254
On the bottom of this page you could find an alternate approach which can draw exactly the number of lines on a given space...

Categories

Resources