react-native构建基本页面2---轮播图+九宫格
配置首页的轮播图
- 轮播图官网
- 运行
npm i react-native-swiper --save安装轮播图组件 - 导入轮播图组件
import Swiper from 'react-native-swiper'; - 其中,在Swiper身上,
showsPagination={false}是用来控制页码的;showsButtons={false}是用来控制左右箭头显示与隐藏;height={160}是用来控制轮播图区域的高度的! - 设置轮播图的样式:
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%'
}
})
- 将组件的代码结构引入到页面上:
<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---轮播图+九宫格的更多相关文章
- React Native学习(六)—— 轮播图
本文基于React Native 0.52 Demo上传到Git了,有需要可以看看,写了新内容会上传的.Git地址 https://github.com/gingerJY/React-Native-D ...
- React中使用CSSTransitionGroup插件实现轮播图
动画效果,是一个页面上必不可少的功能,学习一个新的东西,当然就要学习,如何用新的东西,用它的方法去实现以前的东西啦.今天呢,我就在这里介绍一个试用react-addons-css-transition ...
- Vue(小案例_vue+axios仿手机app)_首页(底部导航栏+轮播图+九宫格)
---恢复内容开始--- 一.前言 1.底部导航(两种做法) 2.轮播图 ...
- 解决ionic2/ionic3轮播图切换页面或者点击过后不自动轮图
我们在ionic2/ionic3开发的过程中会出现切换页面或者滑动切换轮播图出现轮播图不再轮播的情况,这其实需要一些配置. 首先在运用到轮播图的component中引入 import {ViewChi ...
- swiper结合ajax的轮播图
Swiper 是什么:是纯JavaScript打造的滑动特效插件,能够实现触屏焦点图.触屏tab切换.触屏多图切换等常用效果. 开源.免费.稳定.应用广泛. 这就是swiper简单的介绍,由于是结合a ...
- jQuey实现轮播图效果
再平常的浏览器页面,轮播图都是必不可缺少的一个板块,在这总结了一下轮播图基本的一些样式 首先介绍一下,本文实现的轮播图的基本效果: 1. 3s自动切换图片,图片切换时提示点跟随切换 2. 鼠标划到图片 ...
- angularjs1 自定义轮播图(汉字导航)
本来想用swiper插件的,可是需求居然说要汉字当导航栏这就没办法了,只能自己写. directive // 自定义指令: Home页面的轮播图 app.directive('swiperImg', ...
- [Web] 通用轮播图代码示例
首先是准备好的几张图片, 它们的路径是: "img/1.jpg", "img/2.jpg", "img/3.jpg", "img/ ...
- React Native 如何做轮播图 react-native-swiper
//:仿饿了么github:https://github.com/stoneWeb/elm-react-native 欢迎各位同学加入: React-Native群:397885169 大前端群:54 ...
- React Native布局实践:开发京东client首页(三)——轮播图的实现
上篇文章中,我们一起构建了京东client的TabBar.在本文中.将继续向大家介绍京东client首页轮播图及其下发功能button的开发方法,如今就让我们開始吧! 1.相关控件调研 眼下在Gith ...
随机推荐
- Jenkins新建节点找不到通过Java web启动代理?
参考博客:Jenkins新建节点,启动方式没有“通过Java Web启动代理”选项怎么办? 在Jenkins中,打开“系统管理”→“管理节点”→“新建节点”页面时,“启动方式”选项没有“通过Java ...
- 处理jquery 中 给disabled属性不传值的问题
问题:审核页面加入不可编辑的判断后,点击[审核]按钮,报错,form表单的数据没有传递过去. 下面是js中加入的代码,用来判断是否是审核页面的,去掉此代码,点击[审核]按钮能正常传递数据,加入的话,无 ...
- 智和网管平台SugarNMS赋能AI智能化运维
11月14日,由<网络安全和信息化>和IT运维网联合主办的2019(第十届) IT运维大会上海站在锦荣国际大酒店如期召开.运维领域权威专家.技术领袖.各类运维相关技术产品提供商及服务商共同 ...
- docker安装mysql/redis
1.安装mysql容器 #搜索mysql镜像 docker search mysql #拉取mysql镜像 docker pull docker.io/mysql #创建mysql容器,MYSQL_R ...
- 教你用python爬虫监控教务系统,查成绩快人一步!
教你用python爬虫监控教务系统,查成绩快人一步!这几天考了大大小小几门课,教务系统又没有成绩通知功能,为了急切想知道自己挂了多少门,于是我写下这个脚本. 设计思路:设计思路很简单,首先对已有的成绩 ...
- MySql学习-4.查询1
1.基本查询语法: select * from 表名: **注意** 1.select 后写列名,*代表是所有列: 2.列名可以用as起别名,其出现在结果集中: 3.查询多个列,之间用逗 ...
- neo4j学习摘要
参考 链接:https://gitbook.cn/books/5a33782c5778440a9d906017/index.html
- EasyUI表单验证插件扩展
$.extend($.fn.validatebox.defaults.rules, { regex: { validator: function (value, param) { var regex ...
- StackExchange.Redis 系列 1:基础使用
本系列博文已经全部完成,完整系列请访问:https://blog.zhuliang.ltd/tags/StackExchange-Redis%E7%B3%BB%E5%88%97/ 本文转自:https ...
- The ADB binary found at ... 虚拟机运行错误
虚拟机问题,可以说差点扼杀我开发 APP 的乐趣,哼,最后请教了一下辉哥(学长),终于解决 —— 用真机调试.下面是步骤: 首先,检查一下真机连接需要的 SDK 是否安装,未安装,勾选进行安装 接着用 ...