【问题标题】:behaviour of addViewInLayout() of ViewGroup in androidandroid中ViewGroup的addViewInLayout()的行为
【发布时间】:2011-12-05 09:52:15
【问题描述】:

我正在创建自定义ViewGroup,其中我使用onLayout 方法,在该方法中我调用ViewGroupaddViewInLayout(),但它仅水平添加View

如何强制它垂直添加View,就像ListView 为Android 所做的那样

寻求帮助。

【问题讨论】:

    标签: android viewgroup


    【解决方案1】:

    您可以尝试通过

    指定位置
    child.layout(int left, int top, int right, int bottom)
    

    如果你已经测量了视图组中的其他视图,那么你应该可以得到最底部视图的底部

    child.layout(left, viewAbove.getBottom(),right, viewAbove.getBottom()+heightOfTheChild);
    

    【讨论】:

    • 第二行不应该是:child.layout(left, viewAbove.getBottom(), right, viewAbove.getBottom() + heightOfTheChild);
    猜你喜欢
    • 2015-02-05
    • 2014-07-25
    • 1970-01-01
    • 1970-01-01
    • 2021-12-17
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多