react-native-swiper设定高度的方法(设置rn轮播图所占高度)
效果图:

直接上解决方案:
1、在Swiper标签外套一层View
<View style={styles.container}>
<Swiper
style={styles.wrapper}
height={width*40/75}
autoplayTimeout={2.5}
// showButtons —— 是否显示左右翻页按钮
showsButtons={false}
// autoPlay —— 是否自动播放
autoplay={true}
// paginationStyle —— 包含小点点的容器的样式,这里用来调整位置
paginationStyle={styles.paginationStyle}
// dotStyle —— 小点点的样式
dotStyle={styles.dotStyle}
// activeDotStyle —— 当前被激活的小点点的样式
activeDotStyle={styles.activeDotStyle}
>
<Image source={require('../img/mainSwiper/swiper1.jpg')} style={styles.bannerImg} />
<Image source={require('../img/mainSwiper/swiper2.jpg')} style={styles.bannerImg} />
<Image source={require('../img/mainSwiper/swiper3.jpg')} style={styles.bannerImg} />
</Swiper>
</View>
2、在View的style中设置高度
const styles = StyleSheet.create({
container: {
backgroundColor: "#f3f3f3" ,
height:width*40/75,
},
bannerImg: {
height: width*/,
width: width,
},
wrapper: {
width: width,
},
paginationStyle: {
},
dotStyle: {
width: ,
height: ,
backgroundColor:'#fff',
opacity: 0.4,
borderRadius: ,
},
activeDotStyle: {
width: ,
height: ,
backgroundColor:'#fff',
borderRadius: ,
},
});
3、注意style中不要使用flex。
4、完整版轮播图代码(下面即为MainSwiper.js的代码内容)
import React,{Component} from 'react'
import Swiper from 'react-native-swiper';
import {
Image,
View,
StyleSheet,
Dimensions,
} from 'react-native';
let {width} = Dimensions.get('window');
class MainSwiper extends Component{
render(){
return(
<View style={styles.container}>
<Swiper
style={styles.wrapper}
height={width*40/75}
autoplayTimeout={2.5}
// showButtons —— 是否显示左右翻页按钮
showsButtons={false}
// autoPlay —— 是否自动播放
autoplay={true}
// paginationStyle —— 包含小点点的容器的样式,这里用来调整位置
paginationStyle={styles.paginationStyle}
// dotStyle —— 小点点的样式
dotStyle={styles.dotStyle}
// activeDotStyle —— 当前被激活的小点点的样式
activeDotStyle={styles.activeDotStyle}
>
<Image source={require('../img/mainSwiper/swiper1.jpg')} style={styles.bannerImg} />
<Image source={require('../img/mainSwiper/swiper2.jpg')} style={styles.bannerImg} />
<Image source={require('../img/mainSwiper/swiper3.jpg')} style={styles.bannerImg} />
</Swiper>
</View>
)
}
}
const styles = StyleSheet.create({
container: {
backgroundColor: "#f3f3f3" ,
height:width*40/75,
},
bannerImg: {
height: width*40/75,
width: width,
},
wrapper: {
width: width,
},
paginationStyle: {
},
dotStyle: {
width: 22,
height: 3,
backgroundColor:'#fff',
opacity: 0.4,
borderRadius: 0,
},
activeDotStyle: {
width: 22,
height: 3,
backgroundColor:'#fff',
borderRadius: 0,
},
});
export default MainSwiper;
react-native-swiper设定高度的方法(设置rn轮播图所占高度)的更多相关文章
- element-ui中轮播图自适应图片高度
哈哈,久违了各位.我又回来了,最近在做毕设,所以难免会遇到很多问题,需要解决很多问题,在万能的博友帮助下,终于解决了Element-ui中轮播图的图片高度问题,话不多说上代码. 那个axios的使用不 ...
- ReactNative新手学习之路04 组件化开发轮播图swiper支持安卓和IOS
react native 新手之路04 组件化开发轮播图swiper支持安卓和IOS npm install react-native-carousel --save git 地址Properties ...
- swiper 轮播图,拖动之后继续轮播
在此贴出swiper官网地址:https://www.swiper.com.cn/api/index.html 示例如下(官网示例): <script> var mySwiper = ne ...
- React Native 之轮播图swiper组件
注释:swiper组件是第三方组件 所以在使用之前应该先在命令行安装,然后将第三方的模块引入(第三方模块地址:https://github.com/leecade/react-native-swipe ...
- React Native填坑之旅--重新认识RN
如同黑夜里的一道光一样,就这么知道了F8. F8是每年一次Facebook每年一次的开发者大会.每次大会都会release相应的APP,iOS.Android都有.之前都是用Native开发的,但是2 ...
- 微信小程序之swiper轮播图中的图片自适应高度
小程序中的轮播图很简单,官方都有例子的,但是唯一的缺陷就是swiper是固定死的150px高度,这样如果传入的图片大于这个高度就会被隐藏.辣么,怎样让图片自适应不同分辨率捏. 我的思路是:获取屏幕宽度 ...
- React Native学习(六)—— 轮播图
本文基于React Native 0.52 Demo上传到Git了,有需要可以看看,写了新内容会上传的.Git地址 https://github.com/gingerJY/React-Native-D ...
- 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 ...
随机推荐
- 第五章、前端之JQuery
目录 第五章.前端之JQuery 一.选择器 二.基本筛选器 三.样式操作 四.位置操作 五.文本操作 六.属性操作 七.文档处理 八.事件 九.动画效果 十.补充 第五章.前端之JQuery 一.选 ...
- 虚拟机不能桥接联网 vmnet0上的网桥当前未运行
win10家庭版更新到内测版后,原来可以正常桥接工作的虚拟机ubuntu不能在桥接模式下联网和ssh连接了,因为获取不到IP地址了. 上网搜索一下,发现直接粗暴的方法--修复VMware Workst ...
- fnmatch:Unix式glob模式匹配,简单场景下可以代替正则
介绍 fnmatch模块用于根据glob模式(如Unix shell所使用的的模式)比较文件名 简单匹配 import fnmatch ''' fnmatch将一个文件名与一个模式进行比较,并返回一个 ...
- Matlab---绘图中坐标系显示设置
Matlab绘图---坐标系显示设置 [@wp20180507-20180511(week 5)] 目录: 一.设置坐标范围 二.修改坐标轴显示的刻度.密度.lable文字.位置等 三.Matlab绘 ...
- Repeater POJ - 3768 (分形)
Repeater POJ - 3768 Harmony is indispensible in our daily life and no one can live without it----may ...
- inferiors
inferiors 英[ɪnˈfɪərɪəz] 美[ɪnˈfɪriərz] n. 不如别人的人; 级别(或地位)低的人; [词典] inferior的复数; info inferiors
- hbase实践之rowkey设计
rowkey设计的重要性 rowkeys是HBase表设计中唯一重要的一点. rowkey设计要求 唯一性 存储特性 按照字典顺序排序存储 查询特性 由于其存储特性导致查询特性: 查询单个记录: 查定 ...
- Beyond Compare 4 使用30天后过期续用方法
Beyond Compare 4 使用30天后过期续用方法 windows上的Beyond Compare 4软件过期了,两个方法: 方案一: 找到Beyond Compare 4安装目录,安装时默认 ...
- ibatis调用存储过程(无返回参数)
ibatis调用存储过程例子: java: getSqlMapClientTemplate().insert(sql, paraMap) ibatis xml: <parameterMap id ...
- [Python自学] day-18 (2) (MTV架构、Django框架、模板语言)
一.实现一个简单的Web服务器 使用Python标准库提供的独立WSGI服务器来实现MVC架构. 首先,实现一个简单的Web服务器: from wsgiref.simple_server import ...