zoukankan      html  css  js  c++  java
  • getHeight returns 0 for all Android UI objects

    It's 0 because in both onCreate and onStart, the view hasn't actually been drawn yet. You can get around this by listening for when the view is actually drawn:

    final TextView tv =(TextView)findViewById(R.id.venueLabel);
    final ViewTreeObserver observer = tv.getViewTreeObserver();
    observer.addOnGlobalLayoutListener(new OnGlobalLayoutListener()
    {
      @Override
      publicvoid onGlobalLayout()
    { tv.getHeight(); observer.removeGlobalOnLayoutListener(this);
      
    }
    });

    The call to remove the listener is there to prevent repeated invocations of your custom handler on layout changes... if you want to get those, you can omit it.

    http://stackoverflow.com/questions/8170915/getheight-returns-0-for-all-android-ui-objects

  • 相关阅读:
    webpack基本使用
    vue-路由-显示名称
    vue-父组件和路由
    vue-路由
    vue-父子组件和ref
    vue-组件
    go-面向对象编程(上)
    JavaScript的历史
    vue-列表动画
    钩子函数实现小球弹落
  • 原文地址:https://www.cnblogs.com/savagemorgan/p/3659141.html
Copyright © 2011-2022 走看看