我想有两个视图填充整个容器视图,但由于某种原因,我不能以令人满意的方式真正做到 - 我设法做到这一点的唯一方法是使用绝对宽度,这看起来像一个对我不好的做法。有两个视图水平填充容器查看器吗?
我的目标是有一个视图包含几行(gridLine),其中每行包含两个可点击的视图(gridButton)。
这是父视图风格:
gridLine: {
flexDirection: 'row',
alignContent: 'stretch',
backgroundColor: 'grey',
overflow: 'hidden',
}
这是孩子们提出的意见风格:
gridButton: {
alignContent: 'center',
justifyContent: 'center',
alignItems: 'center',
alignSelf: 'stretch',
borderWidth: 1,
borderColor: 'darkgrey',
backgroundColor: '#f9f9f9',
height: 50,
width: '50%', // I tried putting it to null, '100%', nothing works :(
}
这是它的实际使用情况:
<View style={styles.gridLine}>
<TouchableHighlight>
<View style={styles.gridButton}>
<Text>Text1</Text>
</View>
</TouchableHighlight>
<TouchableHighlight>
<View style={styles.gridButton}>
<Text>Text1</Text>
</View>
</TouchableHighlight>
</View>
这是我希望它看起来像:这个问题的
活生生的例子: https://snack.expo.io/SkfLNbiFZ
您可以使用2列的FlatList并根据需要渲染组件。 –
这是一个很好的答案,我已经设法做到这一点。你应该提交它作为答案。 – NadavL