菜要多喝水才會長大

[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 …

Leave a Reply

Looking for something?

Use the form below to search the site:

Still not finding what you're looking for? Drop a comment on a post or contact us so we can take care of it!

Archives

All entries, chronologically...