1
我在这里试图在表格行中获取TextView的宽度设置一些随机文本后。 我使用的是getWidth(),但它始终返回零。有没有办法找出动态创建的TextView的宽度。获取表格行内动态TextView的宽度
这是我的代码。
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
customer_id=(TextView)findViewById(R.id.customer_id);
comapny_name=(TextView)findViewById(R.id.compnay_name);
line1=(ImageView)findViewById(R.id.line1);
TableLayout tl=(TableLayout)findViewById(R.id.linlay);
TableRow tr1 =null;
for(int i=0;i<20;i++)
{
tr1 = new TableRow(this);
tr1.setLayoutParams(new LayoutParams(LayoutParams.FILL_PARENT,LayoutParams.WRAP_CONTENT));
TextView textview = new TextView(this);
textview.setText("data");
textview.setTextColor(Color.YELLOW);
textview.setTextSize(30);
TextView textview1 = new TextView(this);
textview1.setText("data1");
textview1.setTextColor(Color.YELLOW);
textview1.setTextSize(30);
tr1.addView(textview);
tr1.addView(textview1);
tl.addView(tr1);
int width=textview.getWidth();
Log.i("Width",width+"");
}
? – ingsaurabh
基于它的宽度,我必须调整其标题(标题) –