Android studio selecting wrong layouts

后端 未结 2 1918
悲&欢浪女
悲&欢浪女 2020-12-11 14:18

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 androi

相关标签:
2条回答
  • 2020-12-11 14:34

    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)

    0 讨论(0)
  • 2020-12-11 14:37


    You have to write layout once but have to define dimensions dimens.xml for different different resolutions in app>res>values.

    0 讨论(0)
提交回复
热议问题