[RFC] Using DP instead of PX for Android
-
Density-independent pixel (dp) is a virtual pixel unit used in the Android platform. It helps to express layout dimensions or position in a density-independent way. The Android style guide uses DP as the metrics of UI component. Reference : http://developer.android.com/design/style/metrics-grids.html
However, I cannot find any method to use DP on QML provided by the SDK. Therefore, I have written my own solution and wish it can also help others to speed up Android development. As now it is just the first draft, it is not perfect. Therefore, I would like to seek for comment from everybody to help to improve it. So please feel free to suggest any better solution. Thanks.
"Example Code":https://github.com/benlau/junkcode/tree/master/qt/androidmetricdemo
Design and issue
- The conversion from DP to PX is not using the method suggested by QTBUG-11655.
Reason: Passing the unit from context object will break the Qt Designer.
https://bugreports.qt-project.org/browse/QTBUG-11655
- A splash QML is needed.
Unlike the method suggested in #11655 , the conversion is done by a function with static parameter. The parameter must be set before the main scene. That is why it need a splash scene to prepare the parameter.