react native九宫格的实现(具有可扩展性)

封装单独的组件

class Info extends Component{
    render(){
        var index=this.props.index;
        return(
            <TouchableHighlight underlayColor='#eee' onPress={()=>{}} style={styles.touchView}>
                <View style={[styles.singleView]}>
                    <View style={{height:70}}>
                        <View style={{flexDirection:'row',alignItems:'center'}}>
                        </View>
                        <Text style={{marginTop:6,fontSize:14,color:"#999999"}}>未完成</Text>
                    </View>
                </View>
            </TouchableHighlight>
        )
    }
}

实现九宫格(数量没有限制)

export default class accountApply extends Component{
    constructor(props){
        super(props)
    }

    render(){
        console.log(StatusBar.currentHeight)
        var arr=[];
        for(var i=0;i<info.length;i++){
            arr.push( <Info index={i} key={i}/>)
        }
        return(
            <View style={styles.container}>
                <ScrollView>
                    <View style={{padding:10,flexDirection:'row',flexWrap:'wrap'}}>
                        {arr}
                    </View>
                </ScrollView>
            </View>

        )
    }
}

样式如下:

const styles=StyleSheet.create({
    container: {
        flex: 1,
        backgroundColor: '#f0f2f5',
    },
    header:{
        width:Utils.ScreenWidth,
        height:Utils.headerBodyHeight,
        marginTop:Utils.statusHeight,
        alignItems:'center',
        justifyContent:'center'
    },
    headerBg:{
        width:Utils.ScreenWidth,
        height:Utils.headerHeight,
        position:'absolute',
        top: 0,
    },
    headerTitle:{
        fontSize:19,
        color:'#fff',
        backgroundColor:'transparent'
    },
    backView:{
        height:Utils.headerBodyHeight,
        position:'absolute',
        left:15,
        top:Utils.statusHeight,
        flexDirection:'row',
        alignItems:'center'
    },
    backText:{
        marginLeft:5,
        fontSize:15,
        color:'#fff',
        backgroundColor:'transparent'
    },
    submitView:{
        position:'absolute',
        right:15,
        top:Utils.statusHeight,
        justifyContent:'center',
        height:Utils.headerBodyHeight,
    },
    submitText:{
        fontSize:15,
        color:'#fff',
        backgroundColor:'transparent'
    },
    touchView:{
        width:(Utils.ScreenWidth-60)/2,
        backgroundColor:'#fff',
        margin:10,
        borderRadius:5
    },
    singleView:{
        height:100,
        paddingLeft:15,
        borderRadius:5,
        justifyContent:'center',
        overflow:'hidden'

    },
    bgImg:{
        width:74,
        height:62,
        position:'absolute',
        right:-15,
        bottom:-15
    },
    infoName:{
        fontSize:16,
        color:'#444444',
        paddingTop:0
    },
    infoIcon:{
        marginLeft:10,
        width:14,
        height:14
    }

})

效果如下:


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值