【问题标题】:How to get the width and height of the row on the tableLayout如何获取tableLayout上行的宽度和高度
【发布时间】:2011-10-04 19:19:13
【问题描述】:

这里我将宽度和高度设为 0,如何在 tableLayout 中找到行的确切宽度和高度

    tr.addView(txt, params);
    tr.addView(l, lay);


    tr1.addView(txt1, params);
    tr1.addView(l1, lay);

    tr2.addView(btn, params);
    tr2.addView(l2, lay);

    tr3.addView(txt2, params);
    tr3.addView(iV22, lay);

    tl.addView(tr);

    tl.addView(tr1);

    tl.addView(tr2);              
          int height = tr.getHeight();
          Log.d("Height", String.valueOf(height));
          int Width = tr.getWidth();
          Log.d("Width", String.valueOf(Width));
          setContentView(tl);

【问题讨论】:

    标签: android android-layout tablelayout


    【解决方案1】:

    只有在显示活动时才能获取布局大小。尝试获取按钮 ib 您的活动并通过单击按钮获取大小。

    【讨论】:

      【解决方案2】:

      试试这个

      table.getViewTreeObserver().addOnGlobalLayoutListener(new OnGlobalLayoutListener() {
      
                  @Override
                  public void onGlobalLayout()
                  {
                      Log.d("", row.getWidth();
      
                  }
              });
      

      【讨论】:

      • 这可以获取屏幕大小/全局布局,我需要获取行宽和高度。谢谢
      猜你喜欢
      • 2011-07-12
      • 2014-05-01
      • 1970-01-01
      • 2019-12-26
      • 2011-09-25
      • 2012-10-10
      • 2014-07-27
      • 1970-01-01
      • 2011-05-31
      相关资源
      最近更新 更多