RN-子控件自动换行- flexWrap: 'wrap'

7D2281A6-51B7-41BB-B479-27E15D3201EF.png

类似这样的布局,如果一行不够显示的话,自动化将子控件换行到下一行

其实方法很简单,主要是记录下,省的头脑不清醒再给忘了。。。

主要是 flexWrap: 'wrap'这个style

nowrap:
  flex容器为单行。该情况下flex子项可能会溢出容器
wrap:
  flex容器为多行。该情况下flex子项溢出的部分会被放置到新行,子项内部会发生断行
wrap-reverse:
  反转 wrap 排列。
/**
 * Sample React Native App
 * https://github.com/facebook/react-native
 * @flow
 */

import React, { Component } from 'react';
import {
    StyleSheet,
    Text,
    View,
    TouchableOpacity
} from 'react-native';
import PropType from 'prop-types';

export default class imageType extends Component<{}> {

    constructor(props){
        super(props);
    }

    render() {
        return (
            <View style={styles.container}>
                <View style={{ margin: 10, padding: 10, borderRadius: 5, backgroundColor: 'red'}}>
                    <Text>12asdfa3</Text>
                </View>
                <View style={{ margin: 10, padding: 10, borderRadius: 5, backgroundColor: 'red'}}>
                    <Text>12sd3</Text>
                </View>
                <View style={{ margin: 10, padding: 10, borderRadius: 5, backgroundColor: 'red'}}>
                    <Text>1asdfadfadsf23</Text>
                </View>
                <View style={{ margin: 10, padding: 10, borderRadius: 5, backgroundColor: 'red'}}>
                    <Text>1asdf23</Text>
                </View>
                <View style={{ margin: 10, padding: 10, borderRadius: 5, backgroundColor: 'red'}}>
                    <Text>1a23</Text>
                </View>
                <View style={{ margin: 10, padding: 10, borderRadius: 5, backgroundColor: 'red'}}>
                    <Text>12dfdfdfdfdfdfdfdfs3</Text>
                </View>

            </View>
        );
    }
}

/*声明属性*/
imageType.propTypes = {

};

/*属性默认值*/
imageType.defaultProps = {

};

const styles = StyleSheet.create({
    container: {
        backgroundColor: 'black',
        padding: 10,
        flexDirection: 'row',
        flexWrap: 'wrap',
    },
});


最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容

  • Android 自定义View的各种姿势1 Activity的显示之ViewRootImpl详解 Activity...
    passiontim阅读 173,024评论 25 708
  • 选择qi:是表达式 标签选择器 类选择器 属性选择器 继承属性: color,font,text-align,li...
    wzhiq896阅读 1,792评论 0 2
  • 小木屋 红玫清芬绕墙 依稀当年墨痕现 池边清莲 微微风动惊鱼影 竹映清溪 浅浅渔舟自在游 芳草透碧 你的笑容染成天...
    沧海一粟贝阅读 302评论 13 13
  • 花了一天时间设计一套系统的控制器,这套系统不是很复杂,设计起来难度也不是很大。经过三年经验和知识的积累我也完全可以...
    a8c8c2f9c646阅读 206评论 0 0
  • 导语:人在很多时候都是情绪化的,遇到不开心的事或者有时就很莫名其妙的和别人发脾气,不能很好的控制住自己的情绪,还可...
    星空报舍阅读 216评论 0 0