以编程方式在底部定位元素

时间:2013-07-30 14:31:04

标签: android

RelativeLayout.LayoutParams lp = new RelativeLayout.LayoutParams(LinearLayout.LayoutParams.MATCH_PARENT,LinearLayout.LayoutParams.MATCH_PARENT);

lp.addRule(RelativeLayout.ALIGN_PARENT_BOTTOM);

layout.addView(this.adView,lp);

我正在尝试将adView放在屏幕底部。以上似乎只是它的中心。

我想知道我哪里出错了?

2 个答案:

答案 0 :(得分:0)

您将视图定位在底部,但填充整个屏幕,如FD_所述。因此内容以其视图为中心。

答案 1 :(得分:0)

尝试更改:

RelativeLayout.LayoutParams lp = new RelativeLayout.LayoutParams(LinearLayout.LayoutParams.MATCH_PARENT,LinearLayout.LayoutParams.MATCH_PARENT);

为:

RelativeLayout.LayoutParams lp = new RelativeLayout.LayoutParams(RelativeLayout.LayoutParams.WRAP_CONTENT,RelativeLayout.LayoutParams.WRAP_CONTENT);

请注意,我还将LinearLayout更改为RelativeLayout