Reputation: 1297
Im making a game and using surfaceview. I load bitmaps that represent character and background and so on.
But HOW do I properly scale it to fit large devices and small devices and other devices?
//Simon
NOTE* dpi wont work, only pixels work whhen using canvas
Upvotes: 1
Views: 3037
Reputation: 21
Take a look at AndEngine's Cameras. Everything you are looking for can be found there, and it is open source! I have used this engine for a number of games and prototype apps. It is very well documented.
Upvotes: 1
Reputation: 4262
You can implement a helper method that you can use to request calculations based on the device's dpi.
Based on @MitulNakum answer from this qustion, do this:
//note that mdpi is the standard
float getAdjustedDimension(float value){
DisplayMetrics metrics = new DisplayMetrics();
getWindowManager().getDefaultDisplay().getMetrics(metrics);
switch(metrics.densityDpi){
case DisplayMetrics.DENSITY_LOW:
//api 4 and higher
return 0.75 * value;
case DisplayMetrics.DENSITY_MEDIUM:
//api 4 and higher
return value;
case DisplayMetrics.DENSITY_HIGH:
//api 4 and higher
return value * 1.25;
case DisplayMetrics.DENSITY_XHIGH
//api 9 and higher
return value * 2;
case DisplayMetrics.DENSITY_TV
//api 13 and higher
return value * 1.33125;
}
}
Upvotes: 1
Reputation: 1966
The android supported way is by creating several images for each bitmap you need for your app of varying sizes and letting the app decide which to use for a given screen density. Those images would go in the drawable-ldpi, drawable-hdpi, etc, folders. Check out the link and read it closly: http://developer.android.com/guide/practices/screens_support.html
Not very memory friendly though. :(
Upvotes: 0