效果图:

直接上解决方案:

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轮播图所占高度)的更多相关文章

  1. element-ui中轮播图自适应图片高度

    哈哈,久违了各位.我又回来了,最近在做毕设,所以难免会遇到很多问题,需要解决很多问题,在万能的博友帮助下,终于解决了Element-ui中轮播图的图片高度问题,话不多说上代码. 那个axios的使用不 ...

  2. ReactNative新手学习之路04 组件化开发轮播图swiper支持安卓和IOS

    react native 新手之路04 组件化开发轮播图swiper支持安卓和IOS npm install react-native-carousel --save git 地址Properties ...

  3. swiper 轮播图,拖动之后继续轮播

    在此贴出swiper官网地址:https://www.swiper.com.cn/api/index.html 示例如下(官网示例): <script> var mySwiper = ne ...

  4. React Native 之轮播图swiper组件

    注释:swiper组件是第三方组件 所以在使用之前应该先在命令行安装,然后将第三方的模块引入(第三方模块地址:https://github.com/leecade/react-native-swipe ...

  5. React Native填坑之旅--重新认识RN

    如同黑夜里的一道光一样,就这么知道了F8. F8是每年一次Facebook每年一次的开发者大会.每次大会都会release相应的APP,iOS.Android都有.之前都是用Native开发的,但是2 ...

  6. 微信小程序之swiper轮播图中的图片自适应高度

    小程序中的轮播图很简单,官方都有例子的,但是唯一的缺陷就是swiper是固定死的150px高度,这样如果传入的图片大于这个高度就会被隐藏.辣么,怎样让图片自适应不同分辨率捏. 我的思路是:获取屏幕宽度 ...

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

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

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

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

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

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

随机推荐

  1. linux操作系统中的常用命令以及快捷键(一)

    接触了linux系统一年,总结一些常用的命令,快捷键等一些尝试 1.首先查看linux内核数量,常用于编译源码包时 用 make -j 来指定内核数来编译 grep ^processor /proc/ ...

  2. Tenka1 Programmer Contest 2019 D - Three Colors

    Three Colors 思路:dp 设sum为所有边的总和 不能组成三角形的情况:某条边长度>=ceil(sum/2),可以用dp求出这种情况的方案数,然后用总方案数减去就可以求出答案. 注意 ...

  3. 表单重置时 <input type=“hidden”> 隐藏域不可被重置

    可封装全局样式 .hide{ display:none; } 用 <input type="text" class="hide"/> 替代

  4. string::assign

    string (1) string& assign (const string& str); substring (2) string& assign (const strin ...

  5. solr schema.xml配置

    solr使用_version_来做文档的版本控制和修改时加锁(乐观锁) <field name="_version_" type="long" index ...

  6. mysql 5.6zip版本的卸载与5.7 zip 版本的安装

    链接:http://www.imooc.com/article/10359 一 安装环境windows 7 旗舰版mysql-5.6.17-winx64.zip 二 安装过程1.去官网下载mysql- ...

  7. [USACO19JAN]Train Tracking 2——神仙结论题+DP

    原题链接 orz xzz巨佬 首先发现一个结论:两个相邻的\(c\)值如果不相同的话,就可以固定某个位置的值了 这启示我们把连续且相等的\(c\)给单独拿出来看,也就是对于一些\(c_i=c_{i+1 ...

  8. metal cmd执行时间

    https://developer.apple.com/library/archive/documentation/3DDrawing/Conceptual/MTLBestPracticesGuide ...

  9. eclipse调试断点

    1.条件断点 如果你不知道如何添加断点,只需点击左边面板(行号前面)断点即被创建.在调试界面中,“断点”视图会把所有被创建的断点列出来.我们可以给它加一个布尔条件,也就是说,该断点会被激活并且如果布尔 ...

  10. pypdf2:下载Americanlife网页生成pdf合并pdf并添加书签

    初步熟悉 安装 pip install pypdf2 合并并添加书签 #!/usr/bin/env python3.5 # -*- coding: utf-8 -*- # @Time : 2019/1 ...