12
我有一個動態佈局,我有一個按鈕。我怎樣才能將該屬性layout_alignParentBottom
設置爲該按鈕,以便它出現在我的相對佈局的底部?如何將Android屬性layout_alignParentBottom設置爲動態按鈕
或者你知道另一種方式嗎?
我有一個動態佈局,我有一個按鈕。我怎樣才能將該屬性layout_alignParentBottom
設置爲該按鈕,以便它出現在我的相對佈局的底部?如何將Android屬性layout_alignParentBottom設置爲動態按鈕
或者你知道另一種方式嗎?
這隻會在您的佈局是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不要忘記接受有效的答案。 –