这个是效果:

第一步:准备数据源:Car.json

{"data": [{"cars": [{"icon": "m_180_100.png","name": "AC Schnitzer"},{"icon": "m_92_100.png","name": "阿尔法·罗密欧"},{"icon": "m_9_100.png","name": "奥迪"},{"icon": "m_97_100.png","name": "阿斯顿·马丁"}],"title": "A"}........
}

第二步:

import React, {Component} from 'react';
import {AppRegistry,StyleSheet,Text,View,SectionList,Dimensions,Image
} from 'react-native';const dimension = Dimensions.get('window')
var Car = require('./Car.json');var itemWidth = 100;
var cols = 3;
var cMargin = (dimension.width - (itemWidth * cols)) / 4.0;
var rMargin = 12;export default class SectionListView1 extends Component {componentDidMount() {}_renderSectionHeader(info) {return (<View><Text key={info.section.key} style={styles.sectionStyle}>{info.section.title}</Text></View>)}_renderItem(info) {return (<View style={styles.cellStyle}><Image source={{uri: info.item.icon}} style={styles.imageStyle}/><Text>{info.item.name}</Text></View>)}_separatorCom() {return (<View style={{height: 4, width: 500, backgroundColor: 'orange'}}></View>)}render() {var dataSource = [];for (var i = 0; i < Car.data.length; i++) {let datas = [];for (var j = 0; j < Car.data[i].cars.length; j++) {datas.push(Car.data[i].cars[j]);}dataSource.push({key: i, data: datas, title: Car.data[i].title});}return (<View style={styles.container}><SectionListrenderSectionHeader={this._renderSectionHeader}renderItem={this._renderItem}sections={dataSource}// refreshing={false}// onRefresh={()=>{alert("刷新")}}// ItemSeparatorComponent={this._separatorCom}// SectionSeparatorComponent={() => <View style={{height: 20, backgroundColor: 'blue'}}></View>}keyExtractor={(item, index) => ("index" + index + item)}// onEndReached={(info)=>{alert("到达底部")}}// onEndReachedThreshold={0}// stickySectionHeadersEnabled={true}ListHeaderComponent={() => <Viewstyle={{backgroundColor: 'yellow', alignItems: 'center',justifyContent: 'center',width:dimension.width,height:50}}><Text>这个是我的表头</Text></View>}ListFooterComponent={() => <Viewstyle={{backgroundColor: 'red', alignItems: 'center',width:dimension.width}}><Text>这个是我的表尾</Text></View>}contentContainerStyle={styles.sectionListStyle}//设置cell的样式pageSize={4}/></View>);}
}const styles = StyleSheet.create({sectionListStyle: {flexDirection: 'row',flexWrap: 'wrap',alignItems: 'flex-start',backgroundColor: '#dd6ddd',},sectionStyle: {width: dimension.width,padding: 12,backgroundColor: '#21c6cd',color: '#fff'},cellStyle: {alignItems: 'center',borderRadius: 5,borderWidth: 1,borderColor: '#ff496b',marginLeft: cMargin,marginTop:rMargin,marginBottom:rMargin,padding: 6,width:itemWidth},imageStyle: {width: 70,height: 70}})
;module.exports = SectionListView1;

如果大家把上面描述的的SectionList的下面两句代码删除,则会出现单行情况,如果有兴趣,自行调试

contentContainerStyle={styles.sectionListStyle}//设置cell的样式pageSize={4}

renderItem:定义每个元素组件的渲染方式,默认传入参数rowData,要访问其中的"title"可以通过rowData.item.title访问到。
ItemSeparatorComponent:定义每个元素之间分割组件

ListHeaderComponent:定义头部组件
ListFooterComponent:定义底部组件

ListEmptyComponent:data为空时显示的组件

columnWrapperStyle:定义每个组件栏的包裹样式,不支持单行组件
numColumns:number,定义每行显示的元素个数
refreshControl:定义头部刷新组件,例如:
          refreshControl={ //下拉刷新组件
<RefreshControl
refreshing={this.state.refreshing} //通过bool值refreshing控制是否刷新
onRefresh={this._onRefresh.bind(this)} //刷新时需要执行的函数
/>
}
onEndReached:在列表滚动到底部一定距离时调用这个函数,一般在此定义滚动到底部时加载新的数据。
onEndReachedThreshold:决定当距离内容最底部还有多远时触发onEndReached回调。注意此参数是一个比值而非像素单位。比如,0.5表示距离内容最底部的距离为当前列表可见长度的一半时触发。

转载于:https://www.cnblogs.com/hualuoshuijia/p/9803724.html

SectionList的使用相关推荐

  1. React Native 加载多类型布局的实现——分类列表SectionList的封装

    目标:简化及规范SectionList的使用. 实现:基于SectionList的封装. 适用的情况       普通的线布局+列表/分类列表+普通线程布局+列表/分类列表.如下图: 如上图中1.2. ...

  2. ReactNative简介、开发环境、调试、常用组件、useState状态、FlatList组件、SectionList组件、Platform 模块、定义样式、图片组件、触摸事件、打包apk发布版

    ReactNative简介: ReactNative是基于React语法来进行开发移动app的框架: ReactNative中提供了移动端专用的一些组件,我们要使用ReactNative固有的组件代替 ...

  3. React Native FlatList和SectionList列表组件

    FlatList 之前使用的组件是ListView,当时要添加一个下拉刷新,上拉加载的功能,所以对ListView做了一些封装,但是后来看官方文档,不建议再使用ListView,因为效率问题,做过An ...

  4. React Native 之SectionList

    接上一篇: /pages/SectionListDemo.js import React, {Fragment,Component} from 'react'; import {SafeAreaVie ...

  5. React-native学习-8-长列表FlatList和SectionList分组列表

    //8.使用长列表:FlatList组件必须的两个属性是data和renderItem.data是列表的数据源,而renderItem则从数据源中逐个解析数据,然后返回一个设定好格式的组件来渲染 // ...

  6. react-native系列(9)组件篇:最优列表显示方案FlatList和SectionList

    FlatList列表 FlatList是一个高性能的列表组件.原理是:只负责渲染当前可见的列表项,对于不可见的项将不会渲染因为可见的项总是有限的,当一个项被划出屏幕后,被滑出项的容器将会成为新滑入的项 ...

  7. 史上最易懂——ReactNative分组列表SectionList使用详情及示例详解

    React Native系列 <逻辑性最强的React Native环境搭建与调试> <ReactNative开发工具有这一篇足矣> <解决React Native un ...

  8. ReactNative 使用SectionList时出现一个黄色警告VirtualizedList:missing keys for items解决方法

    解决办法:添加一行代码就OK了 _extraUniqueKey(item ,index){return "index"+index+item;} 代码截图:

  9. Java项目:医院预约挂号系统(java+SpringBoot+Maven+Vue+mysql)

    源码获取:博客首页 "资源" 里下载! 一.项目运行 环境配置: Jdk1.8 + Tomcat8.5 + Mysql + HBuilderX(Webstorm也行)+ Eclis ...

最新文章

  1. runtime运行时编程一些相关知识
  2. 用route命令解决Wifi和网卡不能同时上内外网问题
  3. 《2018面向对象程序设计(java)课程学习进度条》
  4. python 为什么元组中只包含一个元素时,需要在元素后面添加逗号?(消除歧义)
  5. 笔记-信息系统安全管理-安全审计
  6. 官方一步解决各种Windows更新问题
  7. cobbler自动化安装Linux系统
  8. c语言编程用进退法求搜索区间代码,用c对函数进行优化的问题
  9. 同态加法_同态的Spotify
  10. 重学前端----前端知识系统学习推荐专栏
  11. MFC空间几何变换之图像平移、镜像、旋转、缩放
  12. GraphX:基于Spark的弹性分布式图计算系统
  13. 1.4 Padding
  14. 软件测试第三次作业junit和Eclemma的使用
  15. 计算机与信息工程学院参与运动会,我院成功举办2018秋季运动会
  16. 利用百度地图坐标拾取系统获取经纬度,并将其坐标转换保存成SHP文件
  17. .h文件、.inc文件、.lib文件的功能及三者之间的异同
  18. python画正切函数_Python
  19. 南通大学python期末考试试卷答案_南通大学大一下学期英语期末考试必考题答(已排版)...
  20. Base64图片转换为图片的方式

热门文章

  1. [POJ] 3687 Labeling Balls(拓扑排序)
  2. C语言 cgi(2)
  3. [转] linux下.tar .gz .tgz .bz2 .bz等解、压包命令详解
  4. 微软System Center 2012推进私有云计算
  5. 语音识别系统及科大讯飞最新实践
  6. 如何使用GIST+LIBLINEAR分类器提取CIFAR-10 dataset数据集中图像特征,并用测试数据进行实验
  7. Vue中的基础过渡动画原理解析
  8. POJ 1260 Pearls
  9. Android网络编程之使用HTTP訪问网络资源
  10. Jdbc连接数据库大全