我正在尝试以编程方式添加 RelativeLayout。布局水平包含一个 imageview 和一个 textview。现在两者都重叠了。如何以编程方式使用 LayoutParams 正确设置对齐方式?
RelativeLayout rl = new RelativeLayout(this);
RelativeLayout.LayoutParams myparam = new RelativeLayout.LayoutParams(
RelativeLayout.LayoutParams.FILL_PARENT,
RelativeLayout.LayoutParams.WRAP_CONTENT);
TextView tv = new TextView(this);
tv.setText("test");
tv.setTextColor(Color.WHITE);
ImageView item = new ImageView(this);
item.setImageResource(image);
myparam.addRule(RelativeLayout.ALIGN_RIGHT);
tv.setLayoutParams(myparam);
rl.addView(item);
rl.addView(tv);