android开发 关于图片位置设置的相关代码

2024-12-16 12:42:16
推荐回答(3个)
回答1:

protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);

RelativeLayout root = new RelativeLayout(this);
root.setLayoutParams(new LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT));
ImageView iv = new ImageView(this);
iv.setImageResource(R.drawable.yourPic);
RelativeLayout.LayoutParams param = new RelativeLayout.LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT);
param.addRule(RelativeLayout.ALIGN_PARENT_BOTTOM, RelativeLayout.TRUE);
param.addRule(RelativeLayout.ALIGN_PARENT_RIGHT, RelativeLayout.TRUE);

root.addView(iv, param);

setContentView(root);
}

回答2:

AbsoluteLayout是android sdk1+时代的事了,现在都4+你还在问?开发中都不用了

回答3:

官方都建议MVC模式,View通过XML来布局了