您的位置:首页 > 其它

从Ubuntu Screen API得到屏幕信息及手机的方向信息

2016-03-22 17:08 1071 查看
我们知道对于一些手机应用来说,能够得到屏幕的尺寸信息已经屏幕的方向,那么对我们的应用的布局非常中.我们可以通过对这个事件的感知,进一步来对我们的应用的布局来重新调整.

下面我们来通过一个简单的例程来显示在Ubuntu
Screen API中有那些信息.

Main.qml

import QtQuick 2.4
import Ubuntu.Components 1.3
import QtQuick.Window 2.2

MainView {
// objectName for functional testing purposes (autopilot-qt5)
objectName: "mainView"

// Note! applicationName needs to match the "name" field of the click manifest
applicationName: "screen.liu-xiao-guo"

width: units.gu(60)
height: units.gu(85)

property var orientations: ["PrimaryOrientation", "PortraitOrientation",
"LandscapeOrientation","", "InvertedPortraitOrientation","", "","",
"InvertedLandscapeOrientation" ]

Page {
title: i18n.tr("screen")

Column {
anchors.centerIn: parent
spacing: units.gu(2)

Label {
text: "desktopAvailableHeight: " + Screen.desktopAvailableHeight
}

Label {
text: "devicePixelRatio: " + Screen.devicePixelRatio
}

Label {
text: "desktopAvailableWidth: " + Screen.desktopAvailableWidth
}

Label {
text: "height: " + Screen.height
}

Label {
text: "width: " + Screen.width
}

Label {
text: "name: " + Screen.name
}

Label {
text: "orientation: " + orientations[Screen.orientation]
}

Label {
text: "primaryOrientation: " + orientations[Screen.primaryOrientation]
}

Label {
text: "orientationUpdateMask: " + Screen.orientationUpdateMask
}

Label {
text: "pixelDensity: " + Screen.pixelDensity
}
}
}
}


在我们的MX4手机上运行我们的应用:





从上面的信息中,我们可以看出来,我们的Screen API给出的所有的信息.细心的开发者将会发现这里得到的信息和我们之前在文章"如何得到屏幕和可用显示区域的大小尺寸及运用分辨率无关的编程"得到的屏幕尺寸是一样的.

整个项目的源码在:https://github.com/liu-xiao-guo/screenapi
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: