配置首页的轮播图

  1. 轮播图官网
  2. 运行npm i react-native-swiper --save安装轮播图组件
  3. 导入轮播图组件import Swiper from 'react-native-swiper';
  4. 其中,在Swiper身上,showsPagination={false}是用来控制页码的;showsButtons={false}是用来控制左右箭头显示与隐藏;height={160}是用来控制轮播图区域的高度的!
  5. 设置轮播图的样式:
var styles = StyleSheet.create({
wrapper: {},
slide1: {
flex: 1,
justifyContent: 'center',
alignItems: 'center',
backgroundColor: '#9DD6EB',
},
slide2: {
flex: 1,
justifyContent: 'center',
alignItems: 'center',
backgroundColor: '#97CAE5',
},
slide3: {
flex: 1,
justifyContent: 'center',
alignItems: 'center',
backgroundColor: '#92BBD9',
},
image:{
width:'100%',
height:'100%'
}
})
  1. 将组件的代码结构引入到页面上:
<Swiper style={styles.wrapper} showsButtons={true} height={160} autoplay={true}>
<View style={styles.slide1}>
<Image source={{uri:'http://www.itcast.cn/images/slidead/BEIJING/2017410109413000.jpg'}} style={styles.image}></Image>
</View>
<View style={styles.slide2}>
<Image source={{uri:'http://www.itcast.cn/images/slidead/BEIJING/2017440109442800.jpg'}} style={styles.image}></Image>
</View>
<View style={styles.slide3}>
<Image source={{uri:'http://www.itcast.cn/images/slidead/BEIJING/2017441409442800.jpg'}} style={styles.image}></Image>
</View>
</Swiper>
import React, { Component } from 'react'
import { View, Text, StyleSheet, Image, TouchableHighlight } from 'react-native' // 导入轮播图组件
import Swiper from 'react-native-swiper'
// 轮播图样式
var styles = StyleSheet.create({
box: {
width: '33.33%',
alignItems: 'center',
marginTop: 15
}
}) // Actions 表示要进行路由的JS操作了,可以跳转到新路由
import { Actions } from 'react-native-router-flux' export default class Home extends Component {
constructor(props) {
super(props)
this.state = {
lunbotu: [] // 轮播图数组
}
} componentWillMount() {
fetch('http://vue.studyit.io/api/getlunbo')
.then(res => res.json())
.then(data => {
// console.warn(JSON.stringify(data, null, ' '))
this.setState({
lunbotu: data.message
})
})
} render() {
return <View> {/* 轮播图的结构 */}
{/* 在 轮播图的 Swiper 组件外面,需要套一层 View,给这个 View 需要手动设置一个高度 */}
<View style={{ height: 220 }}>
<Swiper style={styles.wrapper} showsButtons={true} autoplay={true} loop={true}> {this.state.lunbotu.map((item, i) => {
return <View key={i}>
<Image source={{ uri: item.img }} style={{ width: '100%', height: '100%' }}></Image>
</View>
})} </Swiper>
</View> {/* 在 RN 中,默认,就已经为 所有的 View 启用了弹性和模型,同时,默认的主轴是 纵向的 */}
<View style={{ flexDirection: 'row', flexWrap: 'wrap' }}> <View style={styles.box}>
<Image source={require('../../images/menu1.png')} style={{ width: 60, height: 60 }}></Image>
<Text>新闻资讯</Text>
</View> <View style={styles.box}>
<Image source={require('../../images/menu2.png')} style={{ width: 60, height: 60 }}></Image>
<Text>图片分析</Text>
</View> <View style={styles.box}>
<Image source={require('../../images/menu3.png')} style={{ width: 60, height: 60 }}></Image>
<Text>商品购买</Text>
</View> <View style={styles.box}>
<Image source={require('../../images/menu4.png')} style={{ width: 60, height: 60 }}></Image>
<Text>视频专区</Text>
</View> <TouchableHighlight onPress={this.goMovieList} underlayColor="white" style={styles.box}>
{/* 在 TouchableHighlight 内部,只能放置唯一的一个元素 */}
<View>
<Image source={require('../../images/menu5.png')} style={{ width: 60, height: 60 }}></Image>
<Text>热映电影</Text>
</View>
</TouchableHighlight> <View style={styles.box}>
<Image source={require('../../images/menu6.png')} style={{ width: 60, height: 60 }}></Image>
<Text>联系我们</Text>
</View> </View>
</View>
} // 去电影列表页面
goMovieList = () => {
// 在这里要跳转到电影列表,需要使用 编程式导航
// this.props.history.push
Actions.movielist()
}
}

react-native构建基本页面2---轮播图+九宫格的更多相关文章

  1. React Native学习(六)—— 轮播图

    本文基于React Native 0.52 Demo上传到Git了,有需要可以看看,写了新内容会上传的.Git地址 https://github.com/gingerJY/React-Native-D ...

  2. React中使用CSSTransitionGroup插件实现轮播图

    动画效果,是一个页面上必不可少的功能,学习一个新的东西,当然就要学习,如何用新的东西,用它的方法去实现以前的东西啦.今天呢,我就在这里介绍一个试用react-addons-css-transition ...

  3. Vue(小案例_vue+axios仿手机app)_首页(底部导航栏+轮播图+九宫格)

    ---恢复内容开始--- 一.前言                        1.底部导航(两种做法)                                         2.轮播图 ...

  4. 解决ionic2/ionic3轮播图切换页面或者点击过后不自动轮图

    我们在ionic2/ionic3开发的过程中会出现切换页面或者滑动切换轮播图出现轮播图不再轮播的情况,这其实需要一些配置. 首先在运用到轮播图的component中引入 import {ViewChi ...

  5. swiper结合ajax的轮播图

    Swiper 是什么:是纯JavaScript打造的滑动特效插件,能够实现触屏焦点图.触屏tab切换.触屏多图切换等常用效果. 开源.免费.稳定.应用广泛. 这就是swiper简单的介绍,由于是结合a ...

  6. jQuey实现轮播图效果

    再平常的浏览器页面,轮播图都是必不可缺少的一个板块,在这总结了一下轮播图基本的一些样式 首先介绍一下,本文实现的轮播图的基本效果: 1. 3s自动切换图片,图片切换时提示点跟随切换 2. 鼠标划到图片 ...

  7. angularjs1 自定义轮播图(汉字导航)

    本来想用swiper插件的,可是需求居然说要汉字当导航栏这就没办法了,只能自己写. directive // 自定义指令: Home页面的轮播图 app.directive('swiperImg', ...

  8. [Web] 通用轮播图代码示例

    首先是准备好的几张图片, 它们的路径是: "img/1.jpg", "img/2.jpg", "img/3.jpg", "img/ ...

  9. React Native 如何做轮播图 react-native-swiper

    //:仿饿了么github:https://github.com/stoneWeb/elm-react-native 欢迎各位同学加入: React-Native群:397885169 大前端群:54 ...

  10. React Native布局实践:开发京东client首页(三)——轮播图的实现

    上篇文章中,我们一起构建了京东client的TabBar.在本文中.将继续向大家介绍京东client首页轮播图及其下发功能button的开发方法,如今就让我们開始吧! 1.相关控件调研 眼下在Gith ...

随机推荐

  1. codewars--js--Convert all the cases!

    问题描述: In this kata, you will make a function that converts between camelCase, snake_case, and kebab- ...

  2. Android中通过数组资源文件xml与适配器两种方式给ListView列表视图设置数据源

    场景 实现效果如下 注: 博客: https://blog.csdn.net/badao_liumang_qizhi 关注公众号 霸道的程序猿 获取编程相关电子书.教程推送与免费下载. 实现 将布局改 ...

  3. 7.Android-压力测试、单元测试、日志猫使用

    1.压力测试monkey 通过cmd输入下面命令: adb shell monkey -p com.example.phonecall --ignore-crashes --ignore-timeou ...

  4. Centos7没有IP地址,查看网络状态显示No suitable device found for this connection (devint match))

    今天打开虚拟机,使用 ifconfig 命令时,没有显示出 IP 地址 (更好的阅读体验可访问 这里 ) 使用 systemctl status network 命令查看网络状态 显示没有合适的网络装 ...

  5. 基于SSM开发学生信息管理系统源码

    开发环境:    Windows操作系统开发工具: Eclipse+Jdk+Tomcat+MySql数据库 运行效果图 源码及原文链接:https://javadao.xyz/forum.php?mo ...

  6. Go Web爬虫并发实现

    题目:Exercise: Web Crawler 直接参考了 https://github.com/golang/tour/blob/master/solutions/webcrawler.go 的实 ...

  7. Asp.net core 3.1+EF Core2.2.6+Oracle.EntityFrameworkCore2.1.19连接Oracle数据库

    Asp.net Core 3.1+EF Core2.2.6+Oracle.EntityFrameworkCore2.1.19连接Oracle数据库 1.前言 本次主要采用Asp.net core3.1 ...

  8. Case Study - 用户复购行为预测

    Problem 对于商家来说提前识别回头客是一件集中资源提高新品销售量的头等大事,各大商家为了吸引顾客的二次购买都会实行各种像是促销.优惠券.折扣之类的策略.按理说越了解客户,越知道客户的喜好,越能精 ...

  9. PP: Unsupervised anomaly detection via variational auto-encoder for seasonal KPIs in web applications

    Problem: unsupervised anomaly detection for seasonal KPIs in web applications. Donut: an unsupervise ...

  10. pandas模块的数据操作

    数据操作 数据操作最重要的一步也是第一步就是收集数据,而收集数据的方式有很多种,第一种就是我们已经将数据下载到了本地,在本地通过文件进行访问,第二种就是需要到网站的API处获取数据或者网页上爬取数据, ...