如何更新在Android的修改意见? [英] How to update Android Views upon modifications?

查看:112
本文介绍了如何更新在Android的修改意见?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在查看一些方法,修改某些调用时绘制的形状。在Java中,为了确保组件更新我称之为重绘()。有什么会确保我的观点是正确更新?

我读的地方,叫无效()的onDraw()的方法将让事情最新因此,我也不会需要有像重绘()在我的方法是修改所绘制的形状。

这是正确的,还是有别的东西,我有什么关系?

修改
结果
结果要在例如添加,我在我看来调用一个方法是:

 公共无效setLineThickness(INT厚度){
    aLineThickness =厚度;    如果(aLineThicness→1)
        //重绘(); - 好吧在Java中,但不是在Android的}


解决方案

调用的无效()会告诉它需要重新绘制本身(调用的onDraw)在未来某个时候的观点。所以,如果你在你的看法改变一些东西,比如线条的粗细,调用无效()之后。你知道你的观点,这样最终会被更新。

所有绘图code应的onDraw实施()和你的其他方法应该只是改变你的看法,这将被用来绘制的状态,你叫无效(后)。

I have some methods in my View that modify some of the shapes that are drawn when called. In Java in order to make sure the component is updated I would call repaint(). Is there something that will make sure my view is updated correctly?

I had read somewhere that calling invalidate() in the onDraw() method would keep things up to date and therefore I wouldn't need to have something like repaint() in my methods that modify that shapes that are drawn.

Is this correct, or is there something else I have to do?

EDIT

To add in an example, a method I call in my view is:

public void setLineThickness(int thickness) {
    aLineThickness = thickness;

    if(aLineThicness > 1)
        //repaint();      - Okay in Java but not in Android

}

解决方案

Calling invalidate() will tell the view it needs to redraw itself (call onDraw) sometime in the future. So if you change something in your view, like the line thickness, call invalidate() after it. That way you know your view will eventually be updated.

All your drawing code should be implemented in onDraw() and your other methods should just change the state of your view, which will then be used to draw it, after you call invalidate().

这篇关于如何更新在Android的修改意见?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆