我有3個相對佈局,我需要創建一個單獨的setcontetntview,這是這些佈局的組合,每個組合添加3次並共享相同的屏幕空間,並且需要以編程方式完成。我開始創建一個只增加2個屏幕的新佈局,多次組合3個相對佈局
RelativeLayout primaryLayout = new RelativeLayout(this);
LayoutInflater layoutInflater = (LayoutInflater)this.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
RelativeLayout newLayout = (RelativeLayout)layoutInflater.inflate(R.layout.layout3, null, false);
RelativeLayout newLayout1 = (RelativeLayout)layoutInflater.inflate(R.layout.layout4, null, false);
primaryLayout.addView(newLayout);
primaryLayout.addView(newLayout1);
setContentView(primaryLayout);
這隻顯示layout4。另外,如果我再次添加相同的佈局,它給出的錯誤說明指定的孩子已經有一個家長,你必須先調用父孩子的removeview()。請幫忙!
感謝您的回覆,我添加了規則,但如何讓他們佔據半屏? – bharath 2013-03-15 17:45:22