如何设置的编辑文本框的布局利润率? [英] How to set the layout margins of edit text boxes?

查看:103
本文介绍了如何设置的编辑文本框的布局利润率?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在表格的布局我有一个tablerow的,并在tablerow的我有6编辑文本框,我想设置布局利润率为6编辑文本框

  TableLayout T1 =(TableLayout)findViewById(R.id.table_layout01);  的TableRow TR1 =新的TableRow(inventory.this);
  tr1.setLayoutParams(新的LayoutParams(LayoutParams.FILL_PARENT,LayoutParams.WRAP_CONTENT));
  tr1.setBackgroundColor(Color.BLACK);
  的EditText ED6 =新的EditText(inventory.this);
  //ed6.setLayoutParams(new的LayoutParams(LayoutParams.WRAP_CONTENT,LayoutParams.WRAP_CONTENT));
  /*ViewGroup.MarginLayoutParams editmargin =新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);  ED7的EditText =新的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);  ED8的EditText =新的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 =新的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 =新的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 =新的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);


解决方案

首先你应该知道:根据​​的官方Android开发人员网页,视图(和一个TextView从View派生)不支持保证金的设置,但ViewGroups(如的LinearLayout RelativeLayout的等)做的。

所以你可以做的是以下内容:

  TableLayout.LayoutParams PARAMS =新TableLayout.LayoutParams();
params.setMargins(5,5,5,5);
TextView的视图=新的TextView(本);
view.setLayoutParams(PARAMS);

这会为所有儿童边距为5像素 - 我尝试过了,它(使用的LinearLayout 垂直对齐方式虽然)为我工作。给它一个镜头,让我知道如果我能帮助进一步:)。

干杯,

Ready4Fajir

In the table layout i have a tablerow and in that tablerow i have 6 edit text boxes and i want to set the layout margins for that 6 edit text boxes

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);

解决方案

first of all something you should know: According to the Official Android Dev Pages, Views (and a TextView derives from View) do not support the setting of Margin, but ViewGroups (such as LinearLayout, RelativeLayout etc...) do.

So what you could do is the following:

TableLayout.LayoutParams params = new TableLayout.LayoutParams();
params.setMargins(5, 5, 5, 5);
TextView view = new TextView(this);
view.setLayoutParams(params);

This would set the margin for all children to 5 pixels - I tried it and it worked for me (albeit with a LinearLayout with vertical alignment). Give it a shot and let me know if I can help further :) .

Cheers,

Ready4Fajir

这篇关于如何设置的编辑文本框的布局利润率?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆