1

我正在寻找一种在文本字段(LabelField、EditField 等)中插入表情符号/笑脸/任何位图的方法。从我到目前为止的研究来看,没有直接的方法可以做到这一点,所以我一直试图模拟这种行为。

我正在考虑使用普通文本字段而不是笑脸来插入空格,然后将一些 BitmapFields 放置在笑脸应该在的文本字段上。问题是我没有可靠/快速的方法来找到角色在屏幕上的位置(x,y)。

你能给我一些想法吗?

你能想到解决这个问题的其他方法吗?

我敢肯定,很多人都曾经或那次遇到过这种问题。我希望有人设法找到解决方案。无论多么疯狂/复杂/困难,我都非常渴望接受任何解决方案。

另外,我想在 SDK 5.0 及更高版本中使用它,但我只会满足于 6.0。

4

1 回答 1

3

What you might be able to do is create a custom Manager that is a container for EditFields and BitmapFields. When the user clicks in the initial EditField that is inside of your Manager and begins typing, you let them type until they want an emoticon. When they select it you create a BitmapField right after the EditField and then place a new EditField to the right of the BitmapField. You'll have to keep track of things like when the user hits backspace and empties an EditField, it should be removed, and then they are selecting the BitmapField, and a subsequent backspace would delete the BitmapField and put focus on the previous EditField.

You will have to also create your own EditField that you can control the size of, and BitmapField that allows for backspace to delete it.

As far as I can think ahead, you shouldn't have any problem using this for 5.0

Edit for comments:

You'll have to be implementing your own sublayout() of your Manager in any approach you take, so you know positions because you're the one who put them there. If you want to want to do multi-line (my approach was for single-line), you can do one of three things:

1.) Just have new EditFields for each line and do the linking the same way I talked about where backspace drops you to the previous Field, in this case the last line. You have to keep measurements of how big the field is based off of the text, and see if that will move it to the next line. If it does just adjust where the EditFields are positioned.

2.) You can do your image placement in the multi-line field by implementing your own EditField that expands height, in which case you'll know where the text is and what lines you are on. Drawing the Bitmap would be a matter of calculating (what line number you are) * (font height) and getAdvance(text_up_to_bitmap).

3.) Implement your own EditField where you have a focusable Manager that you manually do all of the drawing. You can parse a String that you save from capturing key strokes and maybe have a flag where an emoticon should be. Draw the text before it, draw the emoticon, then continue drawing the text. The difficulty with this is you will have to do things like determining where the cursor should be, bringing up the virtual keyboard, and handling some of the other tasks that the EditField does for you.

于 2011-05-30T12:56:12.780 回答