css怎么写在stylesheet中无效,写在style里就有效???



  • class MainPage extends Component {
    constructor(props){
    super(props);
    console.log(props);
    this.state={headLayout:0};
    }
    onHeaderLayout(e) {
    console.log(e.nativeEvent.layout.width)
    this.setState({headLayout: e.nativeEvent.layout});
    }
    render(){
    return(
    <View style={{flex:1,paddingTop:64}} onLayout={this.onHeaderLayout.bind(this)}>
    <View style={styles1.header,{height:(this.state.headLayout.width/320*150),}}>
    <Image resizeMode='stretch' source={{uri: 'homepagetitle0'}} style={{flex:1}} />
    </View>
    </View>
    )
    }
    }
    var styles1 = StyleSheet.create({
    //container
    header:{
    backgroundColor:'#F2F2F2',
    borderBottomWidth:0.5,borderColor:'lightgray' //为什么这里无效,写在对应的style位置,就有效
    },



  • <View style={[styles1.header,{height:(this.state.headLayout.width/320*150),}]}>
    这样试一试



  • 是写法的问题,多谢!