0
我想從類動態如何把動態對象視圖中靜線佈局
RelativeLayout r = (RelativeLayout)findViewById(R.id.relative);
dv = new DrawingView(this);
r.addView(dv);
setContentView(R.layout.reportdrawing);
我想從類動態如何把動態對象視圖中靜線佈局
RelativeLayout r = (RelativeLayout)findViewById(R.id.relative);
dv = new DrawingView(this);
r.addView(dv);
setContentView(R.layout.reportdrawing);
你需要選擇或者使用setContentView()
,你的看法將是父, 在一個相對佈局添加一個視圖對象或者將您的視圖添加到相對佈局。
這是一個工作示例。
public class MainActivity extends ActionBarActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.activity.main);
DrawingView drawingView = new DrawingView();
RelativeLayout relativeLayout = (RelativeLayout) findViewById(R.id.relative);
linearLayout.addView(drawingView);
'setContentView(R.layout.reportdrawing);'必須在使用所有'findViewById(...)'調用之前調用。 –