代码之家  ›  专栏  ›  技术社区  ›  Fantius

如何在Android AbsoluteLayout中以编程方式控制子视图的大小

  •  2
  • Fantius  · 技术社区  · 16 年前

    http://code.google.com/android/reference/android/widget/AbsoluteLayout.html

    onLayout(boolean changed, int l, int t, int r, int b)
    //Called from layout when this view should assign a size and position to each of its children. 
    

    @Override
    protected void onLayout(boolean changed, int l, int t, int r, int b) {
        Log.d("test", "In MainLayout.onLayout");
        int childCount = getChildCount();
        for (int childIndex = 0; childIndex < childCount; childIndex++) {
            getChildAt(childIndex).setLayoutParams(new LayoutParams(100, 100, 100, 100));
        }
        super.onLayout(changed, l, t, r, b);
    }
    

    我在XML中声明布局的子元素(按钮)。

    这正确地设置了按钮的位置,但没有设置大小。大小取自XML中定义的内容(这是一个必需的属性)。

    2 回复  |  直到 16 年前
        1
  •  4
  •   Nik Reiman    15 年前

    在你的链接上,它还说

    此类已弃用。

    不要把时间花在让即将被抛弃的东西发挥作用上。此类已弃用。

        2
  •  0
  •   Sharib Tanweer    9 年前

    因为这是绝对的布局。AbsoluteLayout之前已被弃用。