[Android] 在單一 Activity 切換不同 Layout
by GDX on 三月.07, 2010, under 心情日記
首先要先建立一個 LayoutInflater 實體
LayoutInflater mInflater = LayoutInflater.from(this);
接下來把我們需要的 Layouts 透過 inflate 方法讀進來
View mLayoutA = mInflater.inflate(R.layout.A, null);View mLayoutB = mInflater.inflate(R.layout.B, null);
如此就可以在 Activity 內自由切換 Layout 了
setContentView(mLayoutA);// do something …setContentView(mLayoutB);// do something …