react-native style opacity for parent and child

前端 未结 6 1944
再見小時候
再見小時候 2021-02-05 00:03

react-native : I have one View and the child of View is an Image , I applied opacity: 0.5 for View and opacity: 0.9 for an Image but it doesn\'t apply for Image ,the parent opac

6条回答
  •  刺人心
    刺人心 (楼主)
    2021-02-05 00:09

    You can't change parent opacity without affecting child, so you should have absolute positioned background. For proper child positioning, you should add an additional container. Check out this snack: snack.expo.io/SkaHLjzr8

    ...
    
      
        
         
          
        
      
    
    ...
    
    ...
    container: {
        flex: 1,
        justifyContent: 'center',
        paddingTop: Constants.statusBarHeight,
        backgroundColor: '#ecf0f1',
        padding: 8,
      },
      background: {
        ...StyleSheet.absoluteFillObject,
        backgroundColor: 'blue',
        opacity: .5,
        zIndex: 1,
      },
      card: {
        height: 400,
      },
      imageContainer: {
        ...StyleSheet.absoluteFillObject,
        justifyContent: 'center',
        alignItems: 'center',
        zIndex: 2,
        opacity: 0.8,
      },
      image: {
        width: 200,
        height: 200
      }
    ...
    

提交回复
热议问题