requestLayout()没有从onSizeChanged调用时效果()? [英] requestLayout() has no effect when called from onSizeChanged()?

查看:989
本文介绍了requestLayout()没有从onSizeChanged调用时效果()?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个显示文本和图像列,在水平滚动的窗口视图。它重排,从而(至少潜在的)自身的大小作为其内容的变化;它也重排并调整其大小(维持一个基本不变的区域)时,软键盘来得快,去和视图高度的变化。

I have a view that display texts and images in columns, in a horizontally scrolling window. It reflows and thus (at least potentially) resizes itself as its content changes; it also reflows and resizes (maintaining a roughly constant area) when the soft keyboard comes and goes and the view height changes.

我发现的是,调用<一href="http://developer.android.com/reference/android/view/View.html#requestLayout%28%29">requestLayout()工程(在这个意义上,它并触发调用我的<一个href="http://developer.android.com/reference/android/view/View.html#onMeasure%28int,%20int%29">onMeasure()过载)的大部分时间......但是的没有的从我的<一个叫时, href="http://developer.android.com/reference/android/view/View.html#onSizeChanged%28int,%20int,%20int,%20int%29">onSizeChanged()处理程序。

What I found was that calling requestLayout() works (in the sense that it does trigger a call to my onMeasure() overload) most of the time ... but not when called from my onSizeChanged() handler.

我能够解决此通过<一个href="http://developer.android.com/reference/android/view/View.html#post%28java.lang.Runnable%29">post()ing一个 Runnable的那个叫 requestLayout()然后后() ED另一个的Runnable 调用,需要在<$ C运行我的code $ C> onMeasure() ...但是这似乎有点脆弱的(我不希望添加的延迟,但我想确保我的第二个的Runnable 异步后也执行 onMeasure()),也许因为它使这么多经过事件循环,屏幕闪烁太多了。

I was able to work around this by post()ing a Runnable that called requestLayout() and then post()ed another Runnable that called my code that needs to run after the onMeasure() ... but this seems a bit fragile (I don't want to add a delay, yet I do want to be sure that my second Runnable does execute after the async onMeasure()) and, perhaps because it makes so many passes through the event loop, the screen flashes too much.

有没有一些方法 - 以 onSizeChanged() - 以强制 onMeasure()(和可能,另一个 onSizeChanged())以先下一<一发生href="http://developer.android.com/reference/android/view/View.html#onDraw%28android.graphics.Canvas%29">onDraw()?

Is there some way - in an onSizeChanged() - to force an onMeasure() (and, probably, another onSizeChanged()) to happen before the next onDraw()?

推荐答案

我会建议做一个回调类,也许两个

I would suggest making a call back class, maybe two

    interface ImGonnaTellClassBThatClassAdidFinished(){

              void ClassHasFinishedProcessing(String YaySuccess);

              void ClassHasFailedProcessing();    

              void SomethingWackaDoodleHappened(String SomeShyte);       
              }

然后重载类,当你需要它来执行职能

Then Overload the class when you need it to perform functions

     public class FunctionA{
              ImGonnaTellClassBThatClassAdidFinished someName = new  ImGonnaTellClassBThatClassAdidFinished(){
              @Override
              void ClassHasFinishedProcessing(String YaySuccess){
              //Well I should Call class B with the info then
              //Heres Sting YaySuccess, Use it in the right way
              }
              void ClassHasFailedProcessing(){ 
              //Well I failed and should let someone know
              }
              void SomethingWackaDoodleHappened(String SomeShyte){
              //Well Something else happened and I have some info on it
              }
         //Dont forget to pass it to the class
         ClassB doWorkMeow = new ClassB();
         doWorkMeow.hereYouGo(someName);
     }

请确保你打电话回来时,已完成

Make sure you call back when your finished

     class ActivityB(){

     public void hereYouGo(ImGonnaTellClassBThatClassAdidFinished finished){
     String itWorked = new String("Hooray");
     finished.ClassHasFinishedProcessing(itWorked);
     }
 }

希望这会有所帮助,祝你的努力。

Hope this helps, Good Luck in your endeavor.

这篇关于requestLayout()没有从onSizeChanged调用时效果()?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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