【问题标题】:How to set the android property layout_alignParentBottom to a button dynamically如何将android属性layout_alignParentBottom动态设置为按钮
【发布时间】:2014-04-13 04:12:03
【问题描述】:

我有一个动态布局和一个按钮。如何将属性 layout_alignParentBottom 设置为该按钮,以便它出现在我的相对布局的底部?

或者你知道另一种方法吗?

【问题讨论】:

    标签: android dynamic button


    【解决方案1】:

    这仅在您的布局是 RelativeLayout 时才有效,因为其他 ViewGroups 不理解 alignParentBottom。

    RelativeLayout layout = findViewById(R.id.my_relative_layout);
    Button button = new Button(this); // your button
    lp = new RelativeLayout.LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT); // You might want to tweak these to WRAP_CONTENT
    lp.addRule(RelativeLayout.ALIGN_PARENT_BOTTOM);
    layout.addView(button, lp);
    

    【讨论】:

    • 不客气。不要忘记接受一个有效的答案,Nopcea。
    猜你喜欢
    • 1970-01-01
    • 2013-07-28
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多