一個活動,您可以通過以下方式編程方式創建的LinearLayout:如何以編程方式創建自定義視圖的佈局?
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
LinearLayout ll = new LinearLayout(this);
ll.setOrientation(LinearLayout.VERTICAL);
ll.setLayoutParams(new LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT));
TextView tv1 = new TextView(this);
tv1.setText("HELLO");
ll.addView(tv1);
TextView tv2 = new TextView(this);
tv2.setText("WORLD");
ll.addView(tv2);
setContentView(ll);
}
你怎麼做相同的自定義視圖子類中,?有沒有setContentView
或onCreate
方法...
可能是[這一個](http://stackoverflow.com/questions/14054197/how-to-get-the-name-of-textview-included-in-linear-layout-in-onclicklistener) –
參考這個鏈接http://stackoverflow.com/questions/14081339/how-can-i-declare-textview-as-global-variable-to-use-in-other-class/14081472#14081472 –