Reputation: 4721
I'm writing a program for android. I read that the layout-swNdp notation could be used only on SDK 13 level ..But I want the app to adapt to screens 540x960 also on older android versions..like 2.0 2.2 It's possible to do this without using the layout-swNdp folder ?
Upvotes: 1
Views: 271
Reputation: 2232
If you want to do that programatically, you can get the height and width with the Display object:
Display display = ((WindowManager) getSystemService(Context.WINDOW_SERVICE)).getDefaultDisplay();
final int height = display.getHeight();
final int width = display.getWidth();
And get the current API level with:
int currentapiVersion = android.os.Build.VERSION.SDK_INT;
And then you can use a specific layout for those devices by calling setContentView()
under an if condition:
if ((currentapiVersion <= android.os.Build.VERSION_CODES.FROYO) && (height == 960) &&(width == 540)) {
setContentView(R.layout.your_special_layout);
} else {
setContentView(R.layout.your_main_layout);
}
Hope that helps!
Upvotes: 2