【问题标题】:How do I programmatically control the size of a child view in an Android AbsoluteLayout如何以编程方式控制 Android AbsoluteLayout 中子视图的大小
【发布时间】:2010-10-08 09:59:30
【问题描述】:

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 中定义的内容(这是必需的属性)。

【问题讨论】:

    标签: android layout


    【解决方案1】:

    在你的链接上还写着

    此类已弃用。

    不要花时间制作将要被丢弃的东西。这个类已被弃用。

    【讨论】:

      【解决方案2】:

      因为它是AbsoluteLayout。并且 AbsoluteLayout 之前已被弃用。

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2011-07-06
        • 1970-01-01
        • 1970-01-01
        • 2022-01-09
        相关资源
        最近更新 更多