java文本框布局_java – 如何设置编辑文本框的布局边距?

本文介绍了如何在Java的TableLayout中,为表格行内的多个EditText编辑文本框设置布局边距。通过实例展示了如何创建TableRow,设置背景颜色,并为每个EditText设置文本颜色、背景颜色和文本内容,最后将这些文本框添加到表格行中。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

在表格布局中我有一个tablerow,在该tablerow中我有6个编辑文本框,我想为这6个编辑文本框设置布局边距

TableLayout t1=(TableLayout)findViewById(R.id.table_layout01);

TableRow tr1=new TableRow(inventory.this);

tr1.setLayoutParams(new LayoutParams(LayoutParams.FILL_PARENT,LayoutParams.WRAP_CONTENT));

tr1.setBackgroundColor(Color.BLACK);

EditText ed6=new EditText(inventory.this);

//ed6.setLayoutParams(new LayoutParams(LayoutParams.WRAP_CONTENT,LayoutParams.WRAP_CONTENT));

/*ViewGroup.MarginLayoutParams editmargin=new ViewGroup.MarginLayoutParams(ViewGroup.MarginLayoutParams.FILL_PARENT,ViewGroup.MarginLayoutParams.WRAP_CONTENT);

editmargin.setMargins(leftMargin, rightMargin, topMargin, bottomMargin);*/

ed6.setTextColor(Color.BLACK);

ed6.setBackgroundColor(Color.WHITE);

ed6.setText("1");

tr1.addView(ed6);

EditText ed7=new EditText(inventory.this);

//ed7.setLayoutParams(new LayoutParams(LayoutParams.WRAP_CONTENT,LayoutParams.WRAP_CONTENT));

ed7.setTextColor(Color.BLACK);

ed7.setBackgroundColor(Color.WHITE);

ed7.setText("2");

tr1.addView(ed7);

EditText ed8=new EditText(inventory.this);

//ed8.setLayoutParams(new LayoutParams(LayoutParams.WRAP_CONTENT,LayoutParams.WRAP_CONTENT));

ed8.setTextColor(Color.BLACK);

ed8.setBackgroundColor(Color.WHITE);

ed8.setText("3");

tr1.addView(ed8);

EditText ed9=new EditText(inventory.this);

//ed9.setLayoutParams(new LayoutParams(LayoutParams.WRAP_CONTENT,LayoutParams.WRAP_CONTENT));

ed9.setTextColor(Color.BLACK);

ed9.setBackgroundColor(Color.WHITE);

ed9.setText("4");

tr1.addView(ed9);

EditText ed10=new EditText(inventory.this);

//ed10.setLayoutParams(new LayoutParams(LayoutParams.WRAP_CONTENT,LayoutParams.WRAP_CONTENT));

ed10.setTextColor(Color.BLACK);

ed10.setText("5");

ed10.setBackgroundColor(Color.WHITE);

tr1.addView(ed10);

EditText ed11=new EditText(inventory.this);

//ed11.setLayoutParams(new LayoutParams(LayoutParams.WRAP_CONTENT,LayoutParams.WRAP_CONTENT));

ed11.setTextColor(Color.BLACK);

ed11.setText("6");

ed11.setBackgroundColor(Color.WHITE);

tr1.addView(ed11);

t1.addView(tr1);

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值