文本字段的变化将触发全面布局周期 [英] TextField change triggers full layout cycle

查看:111
本文介绍了文本字段的变化将触发全面布局周期的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在注视我的应用程序的性能问题,我发现,每个按键preSS被触发调用全onMeasure()/布局()循环。没有任何理由,我可以看到要尽量奠定了整个应用程序一遍;什么也没有添加或删除,并没有什么改变,我可以看到大小。

While looking at performance problems in my app, I discovered that each button press was triggering a call to the full onMeasure()/layout() cycle. There's no reason that I can see to try to lay out the entire app all over again; nothing has been added or removed, and nothing has changed size that I can see.

问题往往发生在布局非常拥挤,而且它可能是按钮的底行已经超越了屏幕的边缘由一两个像素。

The problem tends to happen when the layout is very crowded, and it's possible that the bottom row of buttons has gone beyond the edge of the screen by a pixel or two.

没有任何人有任何这方面的经验吗?有没有什么办法来确定的为什么的布局周期被触发?

Does anybody have any experience with this? Is there any way to determine why a layout cycle was triggered?

看来,如果没有在屏幕上的文本域被修改的布局不会被触发(见查找的病因在的ViewGroup布局的要求)。是否改变总是一个TextField触发重新布局?我能以某种方式将其锁定为prevent呢?这是令人沮丧认为改变任何文本字段的任何地方在屏幕上可能会导致全面衡量/布局周期级联通过整个应用程序;它的屠杀我的表现。

It seems that the layout won't be triggered if none of the TextFields on the screen are modified (see Finding the cause of a layout request in a ViewGroup). Does modifying a TextField always trigger a re-layout? Can I lock it somehow to prevent this? It's frustrating to think that changing any TextField anywhere on the screen can cause a full measure/layout cycle to cascade through the entire app; it's butchering my performance.

该容器是一个自定义的ViewGroup类,但我不认为这就是问题所在。我看不出有什么我可以做不同的,以保持它被调用。

The container is a custom ViewGroup class, but I don't think that's the problem. I don't see what I could be doing differently to keep it from being called.

我正在考虑增加一个锁的方法来我的小部件prevent初始布局后,进一步布局的变化。这将提高性能,但我宁愿解决根本问题。

I'm considering adding a "lock" method to my widget to prevent any further layout changes after the initial layout. That will improve performance, but I'd rather solve the underlying problem.

下面是堆栈的时候我onMeasure()方法被调用:

Here's the stack at the time my onMeasure() method is called:

Gridbox.onMeasure(INT,INT)线:217
Gridbox(查看).measure(INT,INT)线:8171
的FrameLayout(ViewGroup中).measureChildWithMargins(查看,INT,INT,INT,INT)线:3132 FrameLayout.onMeasure(INT,INT)线:245
的FrameLayout(查看).measure(INT,INT)线:8171
PhoneWindow $ DecorView(ViewGroup中).measureChildWithMargins(查看,INT,INT,INT,INT)线:3132
PhoneWindow $ DecorView(的FrameLayout).onMeasure(INT,INT)线:245
PhoneWindow $ DecorView(查看).measure(INT,INT)线:8171
ViewRoot.performTraversals()线:801
ViewRoot.handleMessage(消息)线:1727
的ViewRoot(处理器).dispatchMessage(消息)线:99 Looper.loop()线:123 ActivityThread.main(字符串[])线:4627
Method.invokeNative(对象,对象[],上课,下课[],类,整型,布尔)行:不可用[本地方法]
Method.invoke(对象,对象...)线路:521
ZygoteInit $ MethodAndArgsCaller.run()线:858
ZygoteInit.main(字符串[])线:616 NativeStart.main(字符串[])行:不可用[本地方法]

Gridbox.onMeasure(int, int) line: 217
Gridbox(View).measure(int, int) line: 8171
FrameLayout(ViewGroup).measureChildWithMargins(View, int, int, int, int) line: 3132 FrameLayout.onMeasure(int, int) line: 245
FrameLayout(View).measure(int, int) line: 8171
PhoneWindow$DecorView(ViewGroup).measureChildWithMargins(View, int, int, int, int) line: 3132
PhoneWindow$DecorView(FrameLayout).onMeasure(int, int) line: 245
PhoneWindow$DecorView(View).measure(int, int) line: 8171
ViewRoot.performTraversals() line: 801
ViewRoot.handleMessage(Message) line: 1727
ViewRoot(Handler).dispatchMessage(Message) line: 99 Looper.loop() line: 123 ActivityThread.main(String[]) line: 4627
Method.invokeNative(Object, Object[], Class, Class[], Class, int, boolean) line: not available [native method]
Method.invoke(Object, Object...) line: 521
ZygoteInit$MethodAndArgsCaller.run() line: 858
ZygoteInit.main(String[]) line: 616 NativeStart.main(String[]) line: not available [native method]

推荐答案

改变一个TextView(其文本)的内容将触发重新布局。然而,这将只会导致的树的一部分措施/布局。如果发生这种情况只能不时地(当用户点击比如一个按钮),请不要担心。

Changing the content of a TextView (its text) will trigger a relayout. This will however only cause a measure/layout of part of the tree. If this happens only from time to time (when the user clicks a button for instance), don't worry about it.

这篇关于文本字段的变化将触发全面布局周期的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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