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 ...
随机推荐
- log4j2 springboot 特点与使用方法
Apache Log4j2 is an upgrade to Log4j that provides significant improvements over its predecessor, Lo ...
- 网络模块axios的简单应用
一.axios的基本使用 例子中使用到的url仅作为示例,不一定有效,想要复现代码需要使用能够提供数据的有效服务器接口url 1.1.什么是axios axios:ajax i/o system:是用 ...
- React之JSX的语法细节
带注释 import React, { Component, Fragment } from 'react' import './style.css' class TodoList extends C ...
- mongoose报错:DeprecationWarning: collection.ensureIndex is deprecated. Use createIndexes instead.
mongoose报错:(node:15689) DeprecationWarning: collection.ensureIndex is deprecated. Use createIndexes ...
- 单页应用(SPA,Single-page-App)和多页应用(MPA,Multi-page App)的区别
单页应用(SPA,Single-page-App)和多页应用(MPA,Multi-page App)的区别 参考博客:https://www.jianshu.com/p/4c9c29967dd6
- ElasticSearch相关概念与客户端操作
一.Elasticsearch概述 Elasticsearch是面向文档(document oriented)的,这意味着它可以存储整个对象或文档(document).然而它不仅仅是存储,还会索引(i ...
- kubernetes监控
总体设计思想 总体设计架构图Kubernetes monitoring architecture 设计介绍 监控分成两个部分 核心指标流程 包括的组件有 kubelet.resource estima ...
- .NET CLI简单使用
官方文档https://docs.microsoft.com/zh-cn/dotnet/core/tools/?tabs=netcore2x 创建新项目 查看能创建什么类型的项目 dotnet new ...
- Java基础之一、入门知识
资料来源于<明解 Java>日本作者 写的很详细 1:命令---java 类名 该命令不是去执行类名.class文件(文件名和类名有可能不一致),切记是表示执行具体的类: 2:“字符”+数 ...
- Electron+Vue – 基础学习(2): 项目打包成exe桌面应用
项目创建完成,启动正常,接下来就是项目打包了.将测试Demo打包成exe桌面应用,点击exe文件,运行项目. 书接上文,创建项目有三种方式 Git拷贝.直接创建:通过electron社群提供的命令行工 ...