SAPUI5获取当前屏幕大小

时间:2018-10-18 10:29:50

标签: sapui5 screen-size

在我的应用程序的特定位置,我需要确定当前的screen size(台式机或平板电脑)。至少我需要屏幕宽度,但是sap.m.ScreenSize会更好。

我该怎么做?提前致谢!

1 个答案:

答案 0 :(得分:2)

function sizeChanged(mParams) {
    switch(mParams.name) {
        case "Phone":
            // Do what is needed for a little screen
            break;
        case "Tablet":
            // Do what is needed for a medium sized screen
            break;
        case "Desktop":
            // Do what is needed for a large screen
    }
}

// Register an event handler to changes of the screen size
sap.ui.Device.media.attachHandler(sizeChanged, null, 
sap.ui.Device.media.RANGESETS.SAP_STANDARD);
// Do some initialization work based on the current size

sizeChanged(sap.ui.Device.media.getCurrentRange(sap.ui.Device.media.RANGESETS.SAP_STANDARD));

我从以下位置获得了此代码:

https://sapui5.hana.ondemand.com/1.54.8/#/api/sap.ui.Device.media

您还将获得有关其工作原理的更详细说明