问题
I am new to Android. I am building my first application.
I have been trying to make it support multiple screens. I have gone through the developers section in android, but, I am not clear at these things.
What is the resolution, I should use for the different drawable folders? (for example an hdpi screen may have 500*600 screen or 1280*1920 screen.)
I have been using layout folders as mentioned in the developers page, like small, normal and the rest, but android keeps on selecting normal layouts for screens like nexus 6p(for which I am guessing large would be appropriate).
Is there any way I could make it look better??
回答1:
You have to write layout once but have to define dimensions dimens.xml for different different resolutions in app>res>values.
回答2:
When you inflate your layout or setting your content view you can try making method on your application if you have base activities or base fragments
//At base activity/fragment
protected boolean isLargeLayout() {
return getResources().getBoolean(R.bool.large_layout);
}
//Then at your real activity/fragment just call
if(isLargeLayout()) {
//Set your layout knowing it's large
}else{
//Normal layout
}
Or use straight something like
if(getResources().getBoolean(R.bool.large_layout)) {
}
Or use dimens.xml with different dps (I do not prefer this method. I like android to choose which is large screen or not)
来源:https://stackoverflow.com/questions/36785364/android-studio-selecting-wrong-layouts