首页 > 解决方案 > (React Native)如何设置边距或填充或宽度或高度?

问题描述

<View style={width: 20}>Hello</View>

平台操作系统?

尺寸.get(“屏幕”)?-> 1100, 1440 ... ?

如何分隔宽度?我希望它在所有设备上看起来都一样,包括 Android 和 iPhone。

标签: react-native

解决方案


如果要设置响应式width,或者width随设备而异width,请使用Dimension. 看看下面的代码:

import {Dimension, StyleSheet} from 'react-native`

.....
<View style={styles.container}>Hello</View>
.....

const styles = StyleSheet.create({
      container:{
          width: Dimension.get('screen').width, // the container will take the whole width of the device screen width
       }
 })

如果您得到答复,请告诉我


推荐阅读