Android 以编程方式将对象与xml中创建的对象对齐
Xml: 我想将此布局放置在et_notes编辑文本下Android 以编程方式将对象与xml中创建的对象对齐,android,layout,Android,Layout,Xml: 我想将此布局放置在et_notes编辑文本下 lp.addRuleRelativeLayout.down,R.id.et_注释;似乎不起作用。除了显示在屏幕顶部外,该布局创建得非常完美。我做不到,但我用另一种方式实现了我想要的。我创建了我想在xml中以编程方式创建的布局,然后扩展了这个布局。这种方法是最简单的,我不需要通过编程来创建布局 llMain是根布局的ID。然后我将要放置在根布局中的布局充气 RelativeLayout relativeLayout = new Relati
lp.addRuleRelativeLayout.down,R.id.et_注释;似乎不起作用。除了显示在屏幕顶部外,该布局创建得非常完美。我做不到,但我用另一种方式实现了我想要的。我创建了我想在xml中以编程方式创建的布局,然后扩展了这个布局。这种方法是最简单的,我不需要通过编程来创建布局 llMain是根布局的ID。然后我将要放置在根布局中的布局充气
RelativeLayout relativeLayout = new RelativeLayout(this);
RelativeLayout.LayoutParams lp = new RelativeLayout.LayoutParams(
RelativeLayout.LayoutParams.FILL_PARENT, RelativeLayout.LayoutParams.WRAP_CONTENT);
relativeLayout.setPadding(5, 5, 5, 5);
relativeLayout.setBackgroundResource(R.drawable.drw_newbucket_item);
lp.addRule(RelativeLayout.BELOW, R.id.et_notes);
ImageView iv=new ImageView(this);
iv.setId(1);
RelativeLayout.LayoutParams lpiv = new RelativeLayout.LayoutParams(
RelativeLayout.LayoutParams.WRAP_CONTENT, RelativeLayout.LayoutParams.WRAP_CONTENT);
iv.setBackgroundResource(R.drawable.ic_action_content_picture);
lpiv.addRule(RelativeLayout.ALIGN_PARENT_LEFT);
TextView tv=new TextView(this);
RelativeLayout.LayoutParams lptv = new RelativeLayout.LayoutParams(
RelativeLayout.LayoutParams.WRAP_CONTENT, RelativeLayout.LayoutParams.WRAP_CONTENT);
lptv.addRule(RelativeLayout.RIGHT_OF, iv.getId());
lptv.addRule(RelativeLayout.CENTER_VERTICAL, relativeLayout.getId());
tv.setLayoutParams(lptv);
tv.setTextSize(16);
tv.setTextColor(Color.parseColor("#000000"));
tv.setText("blabla");
relativeLayout.addView(iv);
relativeLayout.addView(tv);
addContentView(relativeLayout, lp);
RelativeLayout relativeLayout = new RelativeLayout(this);
RelativeLayout.LayoutParams lp = new RelativeLayout.LayoutParams(
RelativeLayout.LayoutParams.FILL_PARENT, RelativeLayout.LayoutParams.WRAP_CONTENT);
relativeLayout.setPadding(5, 5, 5, 5);
relativeLayout.setBackgroundResource(R.drawable.drw_newbucket_item);
lp.addRule(RelativeLayout.BELOW, R.id.et_notes);
ImageView iv=new ImageView(this);
iv.setId(1);
RelativeLayout.LayoutParams lpiv = new RelativeLayout.LayoutParams(
RelativeLayout.LayoutParams.WRAP_CONTENT, RelativeLayout.LayoutParams.WRAP_CONTENT);
iv.setBackgroundResource(R.drawable.ic_action_content_picture);
lpiv.addRule(RelativeLayout.ALIGN_PARENT_LEFT);
TextView tv=new TextView(this);
RelativeLayout.LayoutParams lptv = new RelativeLayout.LayoutParams(
RelativeLayout.LayoutParams.WRAP_CONTENT, RelativeLayout.LayoutParams.WRAP_CONTENT);
lptv.addRule(RelativeLayout.RIGHT_OF, iv.getId());
lptv.addRule(RelativeLayout.CENTER_VERTICAL, relativeLayout.getId());
tv.setLayoutParams(lptv);
tv.setTextSize(16);
tv.setTextColor(Color.parseColor("#000000"));
tv.setText("blabla");
relativeLayout.addView(iv);
relativeLayout.addView(tv);
addContentView(relativeLayout, lp);
llMain = (LinearLayout) findViewById(R.id.llMain);
LayoutInflater inflater = (LayoutInflater) this.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
final LinearLayout proof = (LinearLayout) inflater.inflate(R.layout.proof_newitem, null);
final TextView tv_proof = (TextView) proof.findViewById(R.id.tv_newitem);
tv_proof.setText(filename);
ImageView iv_proof = (ImageView) proof.findViewById(R.id.iv_newitem);
llMain.addView(proof);