我想动态设置TextView的位置(在Java代码中)。 我试过了:
public void add(View view)
{
TextView[] tx = new TextView[3];
FrameLayout layout;
layout = (FrameLayout)findViewById(R.id.framelayout);
for(int i=0; i<3; i++)
{
tx[i] = new TextView(this);
tx[i].setText("9");
tx[i].setId(i);
tx[i].setBackgroundColor(Color.GREEN);
tx[i].setTextColor(Color.GRAY);
//Here I would like set position
layout.addView(tx[i]);
}
}
事先,谢谢。
答案 0 :(得分:0)
//试试这段代码
FrameLayout.LayoutParams params = new FrameLayout.LayoutParams(LayoutParams.FILLPARENT,LayoutParams.WRAP_CONTENT, Gravity.CENTER);
((FrameLayout) findViewById(R.id.mainLayout)).addView(tx[i], params);