zoukankan      html  css  js  c++  java
  • React native 中 SectionList用法

    一、代码

     1 import React, { Component } from 'react';
     2 import {
     3     AppRegistry,
     4     View,
     5     Text,
     6     SectionList,
     7 } from 'react-native';
     8 
     9 
    10 
    11 export default class App extends React.Component {
    12 
    13     constructor(props) {
    14         super(props);
    15     }
    16 
    17     _renderItem = (info) => {
    18         var txt = '  ' + info.item.title;
    19         return <Text
    20             style={{ height: 60, textAlignVertical: 'center', backgroundColor: "#ffffff", color: '#5C5C5C', fontSize: 15 }}>{txt}</Text>
    21     }
    22 
    23     _sectionComp = (info) => {
    24         var txt = info.section.key;
    25         return <Text
    26             style={{ height: 50, textAlign: 'center', textAlignVertical: 'center', backgroundColor: '#9CEBBC', color: 'white', fontSize: 30 }}>{txt}</Text>
    27     }
    28 
    29     render() {
    30         var sections = [
    31             { key: "A", data: [{ title: "爱" }, { title: "啊" }, { title: "奥" }] },
    32             { key: "B", data: [{ title: "不" }, { title: "吧" }, { title: "包" }] },
    33             { key: "C", data: [{ title: "吃" }, { title: "车" }] },
    34             { key: "W", data: [{ title: "王者" }, { title: "王者荣耀" }] },
    35         ];
    36 
    37         return (
    38             <View style={{ flex: 1 }}>
    39                 <SectionList
    40                     numColumns ={3}
    41                     horizontal={false}
    42                     renderSectionHeader={this._sectionComp}
    43                     renderItem={this._renderItem}
    44                     sections={sections}
    45                     ItemSeparatorComponent={() => <View><Text></Text></View>}
    46                     ListHeaderComponent={() => <View style={{ backgroundColor: '#25B960', alignItems: 'center', height: 30 }}><Text style={{ fontSize: 18, color: '#ffffff' }}>通讯录</Text></View>}
    47                     ListFooterComponent={() => <View style={{ backgroundColor: '#25B960', alignItems: 'center', height: 30 }}><Text style={{ fontSize: 18, color: '#ffffff' }}>通讯录尾部</Text></View>}
    48                 />
    49             </View>
    50         );
    51     }
    52 
    53 }

    二、效果图

    点关注各类It学习资源免费送+V 1153553800
  • 相关阅读:
    区块链 超级节点什么鬼?
    堆排序--模版类
    梯度下降算法Python简单试验
    svn: Can't convert string from 'UTF-8' to native encoding
    常用加密算法比较
    快速排序结合插入排序
    无法解析的外部符号
    mysql 远程连接出错问题
    50个C/C++经典面试题
    设计算法找出字符串中重复出现最长的子串
  • 原文地址:https://www.cnblogs.com/binary1010/p/8425684.html
Copyright © 2011-2022 走看看