Tablet or Phone - Android

后端 未结 30 2535
难免孤独
难免孤独 2020-11-22 08:33

Is there a way to check if the user is using a tablet or a phone? I\'ve got problems with my tilt function and my new tablet (Transformer)

30条回答
  •  日久生厌
    2020-11-22 09:05

    I needed to detect the smartphone/tablet only in the layout file, because I'm using the navigation code.

    What I did first was to create a layout-sw600dp directory but it was not working well because it would activate on my Nokia 8 in landscape mode, but the screen height would be too small.

    So, I renamed the directory as layout-sw600dp-h400dp and then I got the desired effect. The h-xxxdp parameter should depend on how much content you want to drop on your layout and as such should be application dependent.

提交回复
热议问题