If what you're trying to do is show a different layout depending on which API version is available on the device, you want to use configuration qualifiers. The specifics for alternative resources are also documented.
The most basic way to do it is to create a layout folder for each API level you want to use, formatted as follows:
res/layout/mylayout.xml (Default)
res/layout-v4/mylayout.xml (Android 1.6)
res/layout-v11/mylayout.xml (Android 3.0)
and so on, where vN
is the API level. The specific API levels can be found on this page.
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…