我想有兩個視圖填充整個容器視圖,但由於某種原因,我不能以令人滿意的方式真正做到 - 我設法做到這一點的唯一方法是使用絕對寬度,這看起來像一個對我不好的做法。有兩個視圖水平填充容器查看器嗎?
我的目標是有一個視圖包含幾行(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