让我们先来看一下官方文档上对地图上的控件布局所给出的属性
从此处我们可以看出,对控件进行定位只给了四个属性,如果我要让一个控件使它处于屏幕的右侧该怎么办,反正是不可能使用left:**rpx的,因为我们要适配各种屏幕的大小,不能写死。
举个栗子,如果我想让一个控件居右侧显示,该怎么办呢?
解决办法用到小程序的api wx.getSystemInfo(),获取窗口的宽高再减去控件的宽高。
wx.getSystemInfo({
success: res => {
that.setData({
winWidth: res.screenWidth,
winHeight: res.screenHeight
})
}
});
position: {
left: that.data.winWidth - 50,
top: 8,
width: 37,
height: 37
},