问题
The thing I want to do is to have different layout for the Sensation and Desire models.
I read things about programming for multiple screens and providing resources for different screen size and density, but this sensation resolutions drive me crazy . I have a layout that works perfectly on HTC Desire; they are placed in the layout and the drawings are placed in hdpi. Everything is working perfectly. The problem comes when I try to run the app on the Sensation, everything is misplaced and looks very ugly.
My question is where to put the Sensation layouts ? What qualifier name should I use for Sensation?
回答1:
Try finding the resolution and the density of the device (Sensation) using the following code.
Display display = getWindowManager().getDefaultDisplay();
DisplayMetrics dm = new DisplayMetrics();
display.getMetrics(dm);
int width = display.getWidth();
int height = display.getHeight();
int density = dm.densityDpi;
String densityString = null;
if(density == DisplayMetrics.DENSITY_HIGH) {
densityString = "HDPI";
} else if(density == DisplayMetrics.DENSITY_MEDIUM) {
densityString = "MDPI";
} else if(density == DisplayMetrics.DENSITY_LOW) {
densityString = "LDPI";
}
Then use you appropriate resource name qualifiers for the drawable and layout folders as in Multiple Screen Support. (e.g.) drawable-large-hdpi, layout-large-hdpi
This is not feasible all the times, since you won't have access to all the devices out there. So it's better to create AVDs with different display configurations based on the table depicted in How to Test Your Application on Multiple Screens from the above given link.
来源:https://stackoverflow.com/questions/7316160/multiple-screens-for-htc-desire-and-htc-sensation