问题
I've developed an app that was supposed to target both the Galaxy Nexus and the Galaxy S3. Both have 720 x 1280 screen resolutions and I have only used 'dp' values in my app. The resources exist in the 'layout-xhdpi' and the 'drawable-xhdpi' folders. Layout looks perfectly fine on the Nexus, but the padding values (in dp) is slightly off on the S3. I assume its because of the bigger screen size on S3 and difference in density.
How can I create a separate folder for Nexus and S3 so I can take into account the different screen sizes?
回答1:
Use this scheme:
For same layout landscape and portrait layout-sw360dp
Only for landscape layout-sw360dp-land
Only for portrait layout-sw360dp-port
I try to say you can use the before clasification creating folders with theses names. The layout located into are loaded in the Galaxy S3 - WXGA720. This is a way for disting the layout for this type of device. Its necesary Android 4.0+.
回答2:
I use sw360dp-long
which the system will use for the GS3 and I use sw360dp
for the Galaxy Nexus.
回答3:
Nexus 4: use sw384dp (768x1280)
Samsung S3: use sw360dp (720x1280)
It should be noted that both do fall into the sw360dp bucket, but some developers might need to make things pixel perfect, so the 384 folder might be needed but should be avoided if you can design a more flexible layout using LinearLayout and "weight" instead of hardcoding dp units.
回答4:
You can get the device model and can set layout.
As following you can get model
String phoneModel = android.os.Build.MODEL;
if(phoneModel.equals("ABC")) {
// SET Ralated Layout
} else if(phoneModel.equals("XYZ")) {
// SET Ralated Layout
}
来源:https://stackoverflow.com/questions/11699761/android-s3-layout-vs-galaxy-nexus-layout