我们知道对于一些手机应用来说,能够得到屏幕的尺寸信息已经屏幕的方向,那么对我们的应用的布局非常中.我们可以通过对这个事件的感知,进一步来对我们的应用的布局来重新调整.
\
下面我们来通过一个简单的例程来显示在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给出的所有的信息.细心的开发者将会发现这里得到的信息和我们之前在文章" 如何得到屏幕和可用显示区域的大小尺寸及运用分辨率无关的编程"得到的屏幕尺寸是一样的.
\
整个项目的源码在: github.com/liu-xiao-gu…
\