React native 平面列表绝对定位行

React native 平面列表绝对定位行,react-native,React Native,我试图从本质上创建一个行的“堆栈”,在这里,它不会垂直或水平滚动项目,而是将所有组件呈现在彼此之上 我的解决方案是使用绝对定位,将每个组件堆叠在另一个组件上 唯一的问题是,绝对定位似乎不适用于平面列表。这是我到目前为止尝试过的,只要你使用任何带有绝对定位的东西,它就会呈现出看起来什么都没有的东西 <FlatList data={[ {key: 'a', color: 'red'}, {key: 'b', color: 'green'} ]} renderItem

我试图从本质上创建一个行的“堆栈”,在这里,它不会垂直或水平滚动项目,而是将所有组件呈现在彼此之上

我的解决方案是使用绝对定位,将每个组件堆叠在另一个组件上

唯一的问题是,绝对定位似乎不适用于平面列表。这是我到目前为止尝试过的,只要你使用任何带有绝对定位的东西,它就会呈现出看起来什么都没有的东西

<FlatList
  data={[
    {key: 'a', color: 'red'},
    {key: 'b', color: 'green'}
  ]}
  renderItem={({item, index}) => (
  <View style={{backgroundColor: item.color,
   position: 'absolute', top: 0, left: 0
  }}>
  <Text>{item.key}</Text>
  </View>
    )}
/>
(
{item.key}
)}
/>

这可能更接近您想要的:

<FlatList
            style={{height:50, position: 'absolute', width: '100%'}}
            data={[
              {key: 'a', color: 'red'},
              {key: 'b', color: 'green'}
            ]}
            renderItem={({item, index}) => (
            <View style={{backgroundColor: item.color,
                height: 50,
                alignItems: 'center',
                justifyContent: 'center'
            }}>
            <Text style={{height: 50}}>{item.key}</Text>
            </View>
              )}
          />
(
{item.key}
)}
/>