Android Killer
Android Killer

Reputation: 18499

Writing fractional numbers in Java or Android

I am rendering the HTML into my project to create this type of image as follows:

desired output

So i write this code as below:

<big>1</big>
<sup>
  <sup>
    <small>
      <small>1</small>
    </small>
  </sup>
</sup>
  /
<sub>
  <small>3</small>
</sub>

But the output looks like this:

actual output

You can see the gap between the number 1 and '/' and also between '/' and 3. any idea how to remove it?

Solution:

Just number values changes

<big>1</big><sup>1</sup>&frasl;<sub>10</sub>

which will look like this as in figure. enter image description here

Hope this will help someone.Thanks guys for your support.

Upvotes: 6

Views: 487

Answers (2)

mezmo
mezmo

Reputation: 2480

It doesn't really address you're issue, and I'll admit I haven't done this in Android yet, though I don't see why it wouldn't work, but what I've done in these sorts of situations before was...cheat. I am a programmer after all ;). Take the text you're having problems with and dynamically generate a nice looking graphic for it, then display that graphic. Designer's have been doing this forever as well, using Flash font substitutions.

Some problems just aren't easily solved the "right" way. hth

Upvotes: 0

matt
matt

Reputation: 9412

The reason you're seeing gaps in between the numerator, separator, and denominator is because you're trying to render three different characters in a plain text string, one after another:

enter image description here

Since you want the fractional elements to behave a little bit differently than standard text behaves, you'll have to look at using something designed especially for displaying these types of symbols. You might want to look at MathML (specifically, the portion dealing with bevelled elements in fractions, and something like JEuclid to do the actual rendering.

Upvotes: 3

Related Questions