【问题标题】:Render flatlist items over each other(overlap)相互渲染平面列表项目(重叠)
【发布时间】:2020-06-04 23:39:41
【问题描述】:

我想实现您在下图中看到的效果,但我不知道让平面列表项相互重叠:

忘记左右图标,我只是在寻求一种方法,让中间容器可以相互渲染卡片。提前 tnx

【问题讨论】:

  • 您是否尝试为项目添加负边距和增量 zIndex?

标签: android reactjs react-native


【解决方案1】:

工作示例:https://snack.expo.io/@msbot01/sponaneous-salsa

export default function App() {
  return (
    <View style={styles.container}>
      <View style={{flexDirection:'row', justifyContent:'flex-end', backgroundColor:'white', paddingTop:10, paddingBottom:10}}>
        <View style={{backgroundColor:'transparent'}}>
          <View style={[styles.shadow, {backgroundColor:'red', borderTopLeftRadius:40, borderBottomLeftRadius:40}]}>
            <Text style={styles.paragraph}>
              First
            </Text>
          </View>
        </View>
        <View style={{backgroundColor:'red', borderBottomWidth:0, borderColor:'white'}}>
          <View style={[styles.shadow, {backgroundColor:'red', borderTopLeftRadius:40, borderBottomLeftRadius:40}]}>
            <Text style={styles.paragraph}>
              second  
            </Text>
          </View>
        </View>
        <View style={{backgroundColor:'red', borderBottomWidth:0, borderColor:'white'}}>
          <View style={[styles.shadow, {backgroundColor:'red', borderTopLeftRadius:40, borderBottomLeftRadius:40}]}>
            <Text style={styles.paragraph}>
              third
            </Text> 
          </View>
        </View>
      </View>

    </View>
  );
}

const styles = StyleSheet.create({
  container: {
    flex: 1,
    justifyContent: 'center',
    paddingTop: Constants.statusBarHeight,
    backgroundColor: '#ecf0f1',
    padding: 8,
  },
  paragraph: {
    margin: 24,
    fontSize: 18,
    fontWeight: 'bold',
    textAlign: 'center',
  },
  shadow:{
    shadowColor: '#000',
    shadowOffset: { width: 0, height: 1 },
    shadowOpacity: 0.8,
    shadowRadius: 4,  
    elevation: 5
  }
});

【讨论】:

  • 它需要稍作修改才能用于平面列表渲染项目,因为例如您的示例中的第一个索引具有与其他索引不同的样式。但它让我知道了如何实现我的组件。 tnx 兄弟
猜你喜欢
  • 2018-01-07
  • 1970-01-01
  • 2017-09-09
  • 1970-01-01
  • 1970-01-01
  • 2021-03-10
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多