reactjs - 在水平平面列表旁边添加图像
问题描述
我对 React Native 很陌生,正在尝试创建一个屏幕,其中有 2x 行图像水平滚动(我已经用 FlatList 完成了,如屏幕截图所示),但我希望在这些图像的左侧有一个更大的图像图片。但是,每当我将图像添加到代码中时,它都会显示在上方,而不是旁边。这是我到目前为止的代码尝试和屏幕截图:
const styles = StyleSheet.create({
container: {
height: '100%',
marginHorizontal: 16 * v,
marginVertical: 16 * v,
justifyContent: 'center',
flexDirection: 'row',
},
smileImage: {
width: 240 * v,
height: 240 * v,
},
})
const HomeView = () => {
return (
<>
<SafeAreaView style={styles.container}>
<ScrollView horizontal>
<Image source={Images.smile} style={styles.smileImage} />
<FlatList
data={[
'1',
'2',
'3',
'4',
'5',
'6',
]}
numColumns={2}
renderItem={() => (
<View
style={{
flex: 1,
height: 150,
width: 150,
borderWidth: 1,
borderColor: 'black',
margin: 20,
}}
/>
)}
/>
</ScrollView>
</SafeAreaView>
</>
)
}
解决方案
您可以使用名为FlatlistlistHeaderComponent
的道具,并且可以在其中添加图像
<Flatlist listHeaderComponent={<Image source={{uri:link of image}}/>}/>
推荐阅读
- google-chrome-extension - 从外部 html 向 chrome 扩展主机发送消息
- php - 用户注册后验证电子邮件,laravel
- go - 如何转储正在运行的 kubelet 的 goroutines 堆栈竞赛
- python - 如何在 Python 中从 Excel 中返回 PrintArea
- reactjs - 在 Babel 中配置内联图像导入
- css - CSS:在媒体查询中组合类名
- php - 如何将新闻发送给特定标签的特定订阅者?
- reactjs - 在登录中使用 react-adal 时出错
- bash - 这个 bash 快捷方式是什么?
- latex - 带有 outreg2 的表标题