react-native - 仅将 backgroundColor 和高度/阴影应用于 FlatList 的项目容器(不包括标题)
问题描述
我需要backgroundColor
and elevation
/shadow*
仅应用于FlatList
项目容器,而不是标题。如果FlatList
样式已elevation
设置,阴影将位于整个列表的边界:项目和标题作为一个整体,但如果仅项目容器,我需要它位于边界。这是可能的还是有什么技巧可以做到这一点?
解决方案
您需要将所需样式应用于项目本身,而不是 FlatList 组件:
<FlatList
data={[{ name: 'item1' },{ name: 'item2' },{ name: 'item3' }]}
keyExtractor={(item, index) => `${index}`}
renderItem={({ item }) =>
<View
style={{
shadowColor: 'rgb(0, 0, 0)',
shadowOffset: {
width: 3,
height: 3,
},
shadowOpacity: 0.5,
shadowRadius: 5,
elevation: 2,
backgroundColor: 'white',
padding: 10,
margin: 10,
}}
>
<Text>
{item.name}
</Text>
</View>
}
/>
使用 FlatList 的contentContainerStyle属性在 FlatList中添加一些填充,这样项目的阴影就不会被 FlatList 的边界切断
推荐阅读
- r - 如何使用相互列重新排序不同的列组以相互对齐
- c++ - 按下QPushButton时如何找到动态创建的QLineEdit
- svelte - svelte : on:click 事件获取 API 但不呈现
- c++ - 模拟嵌入式单元测试时出错“重载函数的地址与所需的类型‘void()’不匹配
- asp.net-mvc - 我无法安装“ReportViewerMVC 12.0.0”。我不断收到此错误。请问有人吗?
- wordpress - 从 HTTP 重定向到 HTTPS 删除 url 中的斜杠
- jquery - jQuery:如何在多个文件之间使用 $(this) 选择器?
- scheme - 两个方案“无限循环的制造者”之间的区别?
- javascript - I wrote javascript with ES6, but It's not working in IE. How could I change old version of javascript
- swiftui - Why can I not use append to create an array in SwiftUI