How to set numbers as images on TextView?

2019-07-08 02:54发布

I made a display, that will show the sum of purchase. It's a TextView with background image. I have a designed digits too. How can I set those digit images to that TextView or do I have to create some layout instead of simple TextView? If I need to create layout, can you add some code sample, how can I do it?

Here's an example what I want to achieve.

enter image description here

Regards, evilone

2条回答
地球回转人心会变
2楼-- · 2019-07-08 03:34

As far as I know, your two options would be to create your own True/OpenTypeFont (setting the color of the text to yellow in xml most likely) or to code your own custom ViewGroup which will take a String and convert each character to the appropriate image.

If you're able to construct your own font, you can add a font folder inside your assets project folder, and put your font in it. It can then be loaded like this:

Typeface tf = Typeface.createFromAsset(myContext.getAssets(), "fonts/MyFont.ttf");
myTextView.setTypeface(tf);

This site has free fonts even for commercial use, http://www.fontsquirrel.com and I searched for led and found a font called radioland that looks good, though the numbers are at an angle. If you do use that site, I've found it's good to verify the font is indeed free to use with it's included license or a software and can open the font and view it's headers.

查看更多
Anthone
3楼-- · 2019-07-08 03:36

Install and use the National Instruments 7 Segment LED font. For the Pound symbol, you can make a tabular layout and put it in a corner.

查看更多
登录 后发表回答