動態建立ImageView檢視

android2me發表於2012-11-11
RelativeLayout r = new RelativeLayout(this);
ImageView mImageView = new ImageView(this);
mImageView.setImageResource(R.drawable.xxx);
RelativeLayout.LayoutParams params = new RelativeLayout.LayoutParams(15, 15);
params.addRule(RelativeLayout.ALIGN_PARENT_TOP);
params.addRule(RelativeLayout.ALIGN_PARENT_RIGHT);
mImageView.setLayoutParams(params);
r.add(mImageView);

在這段程式碼中藥注意addRule方法的使用。

相關文章