我有一個自定義視圖類(用於繪圖的畫布)。當我希望它佔據整個屏幕,我實例化類並調用的setContentView像這樣:設置具有自定義視圖的佈局
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
drawingPanel = new DrawingPanel(this);
setContentView(drawingPanel);
}
然而,當我想在屏幕上的XML佈局(activity_make.xml)基地說2元素,一個按鈕和一個佔位符,如何將我的自定義視圖「粘」到視圖佔位符中?
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_make); // the layout which has a button and a placeholder view
drawingPanel = new DrawingPanel(this); // instantiating my canvas
View drawPanelPlaceholder = (View) findViewById(R.id.drawingview);
// how do i stick the drawingPanel into the drawPanelPlaceholder?
}
還是有更好的方法來解決這個問題嗎?有關此文檔的鏈接也感謝!
由於雄激素!任何想法最後一次對drawingPanel的引用是否返回null? – Hoff
我不確定。但使用xml文件編輯您的問題,並使用drawingpanel類創建您的問題。讓我看看我是否幫助。 –