Android studio selecting wrong layouts

大憨熊 提交于 2019-11-27 08:39:48

问题


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.

  1. 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.)

  2. 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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!