Android:将imageview设置为relativelayout的底部

时间:2011-12-06 05:18:53

标签: android android-layout

 RelativeLayout overlay = new RelativeLayout(this);
            addContentView(overlay, new LayoutParams(LayoutParams.FILL_PARENT, px));
            overlay.setBackgroundColor(Color.BLACK);


            border = new ImageView(this);
            border.setImageResource(R.drawable.featured_bar);
            border.setLayoutParams(new LayoutParams(LayoutParams.FILL_PARENT, LayoutParams.WRAP_CONTENT));

            overlay.addView(border);

我希望我的边框imageview位于我的relativelayout 的底部, programmatically 或当然。

基本上,我希望我的装饰边框处于相对于分辨率的某个位置,因为我不知道如何使用x y值进行定位,所以我采用了这种方法。

1 个答案:

答案 0 :(得分:1)

尝试类似

的内容
RelativeLayout.LayoutParams params = new RelativeLayout.LayoutParams(RelativeLayout.LayoutParams.WRAP_CONTENT, RelativeLayout.LayoutParams.WRAP_CONTENT);
params.addRule(RelativeLayout.ALIGN_PARENT_BOTTOM, RelativeLayout.TRUE);
overlay.setLayoutParams(params);

查看this postthis one