美文网首页
RN之使用滚动视图

RN之使用滚动视图

作者: 一只西西狸 | 来源:发表于2019-10-11 16:53 被阅读0次

ScrollView是一个通用的可滚动的容器,你可以在其中放入多个组件和视图,而且这些组件并不需要是同类型的。ScrollView不仅可以垂直滚动,还能水平滚动(通过horizontal属性来设置)。
下面的示例代码创建了一个垂直滚动的ScrollView,其中还混杂了图片和文字组件。

import React, { Component } from 'react';
import { ScrollView, Image, Text } from 'react-native';

export default class IScrolledDownAndWhatHappenedNextShockedMe extends Component {
  render() {
      return (
        <ScrollView>
          <Text style={{fontSize:96}}>Scroll me plz</Text>
          <Image source={{uri: "https://facebook.github.io/react-native/img/favicon.png", width: 64, height: 64}} />
          <Image source={{uri: "https://facebook.github.io/react-native/img/favicon.png", width: 64, height: 64}} />
          <Image source={{uri: "https://facebook.github.io/react-native/img/favicon.png", width: 64, height: 64}} />
          <Image source={{uri: "https://facebook.github.io/react-native/img/favicon.png", width: 64, height: 64}} />
          <Image source={{uri: "https://facebook.github.io/react-native/img/favicon.png", width: 64, height: 64}} />
          <Text style={{fontSize:96}}>If you like</Text>
          <Image source={{uri: "https://facebook.github.io/react-native/img/favicon.png", width: 64, height: 64}} />
          <Image source={{uri: "https://facebook.github.io/react-native/img/favicon.png", width: 64, height: 64}} />
          <Image source={{uri: "https://facebook.github.io/react-native/img/favicon.png", width: 64, height: 64}} />
          <Image source={{uri: "https://facebook.github.io/react-native/img/favicon.png", width: 64, height: 64}} />
          <Image source={{uri: "https://facebook.github.io/react-native/img/favicon.png", width: 64, height: 64}} />
          <Text style={{fontSize:96}}>Scrolling down</Text>
          <Image source={{uri: "https://facebook.github.io/react-native/img/favicon.png", width: 64, height: 64}} />
          <Image source={{uri: "https://facebook.github.io/react-native/img/favicon.png", width: 64, height: 64}} />
          <Image source={{uri: "https://facebook.github.io/react-native/img/favicon.png", width: 64, height: 64}} />
          <Image source={{uri: "https://facebook.github.io/react-native/img/favicon.png", width: 64, height: 64}} />
          <Image source={{uri: "https://facebook.github.io/react-native/img/favicon.png", width: 64, height: 64}} />
          <Text style={{fontSize:96}}>What's the best</Text>
          <Image source={{uri: "https://facebook.github.io/react-native/img/favicon.png", width: 64, height: 64}} />
          <Image source={{uri: "https://facebook.github.io/react-native/img/favicon.png", width: 64, height: 64}} />
          <Image source={{uri: "https://facebook.github.io/react-native/img/favicon.png", width: 64, height: 64}} />
          <Image source={{uri: "https://facebook.github.io/react-native/img/favicon.png", width: 64, height: 64}} />
          <Image source={{uri: "https://facebook.github.io/react-native/img/favicon.png", width: 64, height: 64}} />
          <Text style={{fontSize:96}}>Framework around?</Text>
          <Image source={{uri: "https://facebook.github.io/react-native/img/favicon.png", width: 64, height: 64}} />
          <Image source={{uri: "https://facebook.github.io/react-native/img/favicon.png", width: 64, height: 64}} />
          <Image source={{uri: "https://facebook.github.io/react-native/img/favicon.png", width: 64, height: 64}} />
          <Image source={{uri: "https://facebook.github.io/react-native/img/favicon.png", width: 64, height: 64}} />
          <Image source={{uri: "https://facebook.github.io/react-native/img/favicon.png", width: 64, height: 64}} />
          <Text style={{fontSize:80}}>React Native</Text>
        </ScrollView>
    );
  }
}

ScrollView适合用来显示数量不多的滚动元素。放置在ScrollView中的所有的组件都会被渲染,哪怕有些组件因为内容太长被挤出了屏幕外。如果你需要显示较长的滚动列表,那么应该使用功能差不多但性能更好的FlatList组件。

相关文章

  • RN之使用滚动视图

    ScrollView是一个通用的可滚动的容器,你可以在其中放入多个组件和视图,而且这些组件并不需要是同类型的。Sc...

  • UIScrollView+欢迎界面

    滚动视图(尽量少使用StoryBoard,如果使用了故事版添加滚动视图,在滚动视图里添加控件时不要拉约束) 1` ...

  • 2018-08-17

    工作 掌厨列表接口接入,完成了列表图片的展示。 学习 1.RN中 ScrollView:滚动视图,在屏幕之外的视图...

  • RN的ScrollView和ListView

    1、ScrollView组件 RN封装了Android与IOS两大操作系统提供的滚动视图组件,该组件支持RN组件V...

  • IOS开发 滚动视图高级功能

    本节学习内容: 1.滚动视图的高级属性 2.滚动视图的协义函数 3.滚动视图的高级使用 【ViewControll...

  • RN ScrollView循环滚动视图

    在APP页面中,首页往往会显示一个banner视图,定时循环滚动。那么类似于这样的一个广告展示功能,RN如何实现呢...

  • ScrollView

    高级控件之滚动视图(ScrollView)

  • UIScrollView常用方法

    -指定滚动视图的滚动尺寸。滚动视图正常工作必须要指定滚动视图的滚动尺寸 scrollView.contentSiz...

  • RecyclerView

    RecyclerView 滚动视图 强大的滚动视图,具有强大的布局功能。 滚动视图组成 每个滚动视图通常需要6部分...

  • flutter视图

    PageView滚动视图 使用PageView.builder方式构造视图 直接添加在PageView的child...

网友评论

      本文标题:RN之使用滚动视图

      本文链接:https://www.haomeiwen.com/subject/ruqxmctx.html