你多久可以更新不惹一个TextView多久、TextView

2023-09-06 02:13:41 作者:放肆的年华

假设一个TextView

Suppose a textview

TextView tvSum = findViewById(R.id.sumTexviewId);

如果我想改变显示的文本,我这样做:

If I want to change the displayed text, I do this:

tvSum.setText("£0.00");

现在,假如我经常这样做,说的每一次按键pressed,或许显示出进入一个直到总和。在本例中,preSS之一,它说:1P,那么preSS二和它说:12P等。

Now, supposing I do this regularly, say every time a button is pressed, perhaps showing the sum entered on a till. In this example, you press one, it says "1p", then you press two and it says "12p" and so on.

我发现,如果我这样做,文字变成了一段时间后变形。对于序列12345,一开始就将所有好:

I find that if I do this, the text becomes distorted after a while. For the sequence 12345, to start with all is good:

(pssed但没有$ P $) (1pressed) (当时为2pressed) (然后是3pressed)

不过,在那之后事情变得复杂:

However, after that things get messy:

(然后是4pressed) (当时5pressed)

它从来没有得到任何好转之后。我还没有贴code,因为code真的很简单:一系列按钮,只写一短串一个TextView的 - 没有在code应引起这一点,说实话。 (是的,我已经检查被写入该字符串是通过把它挂在面包正确的。)有没有其他人遇到这个,如果是的话有什么解决的呢?

It never gets any better thereafter. I haven't posted code because the code really is very simple: a bunch of buttons and only writing one short string to one textview - nothing in the code should cause this, honest. (Yes, I've checked the string being written is correct by putting it up on Toast.) Has anyone else come across this, and if so what resolved it?

推荐答案

原来 Mr.Me 是找对了方向,它必须是与当文本改变时,背景呈现方式。我已成立(故意)按钮具有黄色的轮廓(而不是把它未指定)内的透明背景,用色00000000。

It turned out that Mr.Me was looking in the right direction, and it had something to do with the way the background is rendered when the text is changed. I had set (intentionally) the button to have a transparent background inside the yellow outline (rather than leaving it unspecified), using colour 0x00000000.

由于某些原因,采用非完全不透明填充的时候,新的背景铺设在previous内容(约3位图一个周期,我觉得),而不是定义的内容。我想,这可能是由于使用的帆布默认PorterDuff传输模式。

For some reason, when applying non fully opaque fills, the new background is laid over the previous contents (a cycle of about 3 bitmaps, I think), rather than defining the contents. I guess that this is probably due to the default PorterDuff transfer mode used by Canvas.

解决方案我想出了,而工作了这一点:

Solutions I have come up with whilst working this out:

将背景不详。这也是透明的,但由于某些原因积极如此。 有任何全alpha背景。 (缺点:如果你想要一些透明度不工作) 在写这将覆盖的OnDraw 调用之前的 super.onDraw()。 (下行:这种摆脱对这种观点的任何背景,但保留这背后查看次数 Leave the background unspecified. This is also transparent, but for some reason actively so. Have any full alpha background. (Downside: doesn't work if you want some transparency) Write a custom view which overrides onDraw to actively fill the canvas with 0x00 before calling the super.onDraw(). (Downside: this gets rid of any background in this view, but retains Views behind this View.

道歉了没有做任何幻想的声明 - 我并没有意识到,积极设置背景为透明算作花哨!

Apologies for the "not doing anything fancy" statement - I didn't realise that actively setting the background to transparent counted as fancy!

 
精彩推荐