【发布时间】:2021-08-23 10:02:06
【问题描述】:
我的屏幕设置类似于下面的代码
import React from 'react';
import { StyleSheet, View } from 'react-native';
const App = () => {
const styles = StyleSheet.create({
navContainer:{
height:64,
backgroundColor:'#333333',
},
rowsContainer:{
backgroundColor:'red',
margin:0,
padding:0,
},
});
return (
<View>
<View style={styles.navContainer} />
<View style={styles.rowsContainer}>
<ChildrenRow />
<ChildrenRow />
<ChildrenRow />
<ChildrenRow />
<ChildrenRow />
<ChildrenRow />
<ChildrenRow />
<ChildrenRow />
<ChildrenRow />
<ChildrenRow />
</View>
</View>
);
};
export default App;
儿童行
const ChildrenRow = () => {
return (
<View
onLayout={(event) => {
const {width, height} = event.nativeEvent.layout;
console.log(`Height/Width= ${height} and ${width}`)
}}
style={{
height:59,
width:400,
backgroundColor:'black',
margin:0,
padding:0,
}}/>
)
}
尽管没有边距(也没有填充,特意添加margin:0, padding:0),红色背景的视图在我的OPPO F9 上可见,在childrenRows 之间。在其他一些设备以及一些 Firebase 测试设备上也观察到了同样的情况。
使用 Android Studio 的布局检查器显示了更糟糕的结果,如下图所示
还在控制台上注意到,一些childrenRows 的高度奇怪地四舍五入:
here 提出了类似的问题,但我无法使用该解决方案,因为我将在每个子行添加 borderWidth,并且高度是非静态的,这可能会破坏 UI。
【问题讨论】:
标签: css react-native