nativescript - 根据设备高度动态调整 ScrollView 中 Nativescript ContentView 的大小

标签 nativescript nativescript-vue

我有一个 Nativescript Vue 组件模板定义为:

<ScrollView>
    <StackLayout>
        <ContentView ref="mapContainer" height="500" width="100%">
            <Mapbox
            accessToken="my access key"
            mapStyle="outdoors-v9"
            hideCompass="true"
            zoomLevel="10.2" , 
            latitude="51.949266"
            longitude="-12.183571"
            showUserLocation="true"
            disableZoom="true"
            disableRotation="true"
            disableScroll="true"
            disableTilt="true"
            @mapReady="onMapReady($event)">
            </Mapbox>
        </ContentView>
        <Label text="A test label"/>
    </StackLayout>
</ScrollView>

安装组件后,我想将 mapContainer 的高度设置为屏幕高度的大约 75%。为此,我有:

export default {
    name: "MyPage",

    mounted () {
        this.$refs.mapContainer.height = platform.screen.mainScreen.heightDIPs
    }

    ...

}

但这没有任何作用,并且 ContentView 仍保持 500dp 高。

height 本来是一个 setter ,但我想我缺少重绘(?)以使此更改生效,但不确定如何?

最佳答案

为了通过引用访问 ContentView,您必须使用 .nativeView 属性。

this.$refs.mapContainer.nativeView.height = platform.screen.mainScreen.heightDIPs

此外,您不必计算高度,只需以百分比(70%)而不是固定值(500)设置高度,或者使用具有 7 个分区(7*)的 GridLayout。

关于nativescript - 根据设备高度动态调整 ScrollView 中 Nativescript ContentView 的大小,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53484014/

相关文章:

javascript - 如何在 Nativescript 应用程序中调用 axios/api 调用

javascript - Nativescript - 应用程序关闭时运行代码

android - native 脚本 + Vue : sync only works the first time on both device and emulator

pdf - 在 NativeScript 应用程序中生成和显示 PDF

ios - Nativescript-Vue IOS 安全区域布局问题

ios - 无法成功准备 iOS

typescript - Nativescript-vue + Typescript - HMR 不适用于 Vue 类组件

Nativescript RadSideDrawer 卡住

css - 无法解析 CSS

android - Nativescript android删除操作栏