欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页

ReactNative学习记录

程序员文章站 2022-07-16 14:50:01
...

滚动条

横向滚动:

//在ScrollView里面加上这段代码即可
 horizontal={true}

隐藏滚动条:

//隐藏水平
showsHorizontalScrollIndicator = {false}
//隐藏垂直
showsVerticalScrollIndicator = {false}

轮播图示例

import React, {Component} from 'react';
import {
    StyleSheet,
    View,
    Image,
} from 'react-native';
import Dimensions from 'Dimensions';
import Swiper from 'react-native-swiper';

var screenWidth = Dimensions.get('window').width;

export default class SwiperScreen extends Component {
    render() {
        return (
            <View style={styles.lunbotu}>
                <Swiper
                    style={styles.wrapper}
                    height={240}
                    autoplay={true}
                    loop={true}
                    keyExtractor={(item, index) => index + ''}
                    index={1}
                    autoplayTimeout={3}
                    horizontal={true}
                    onMomentumScrollEnd={(e, state, context) => {
                    }}
                    dot={<View style={styles.dotStyle}/>}
                    activeDot={<View style={styles.activeDotStyle}/>}
                    paginationStyle={{
                        bottom: 10
                    }}>
                    <View>
                        <Image style={{width: screenWidth, height: 150}}
                               resizeMode="stretch"
                               source={{uri: ''}}>
                        </Image>
                    </View>
                    <View>
                        <Image style={{width: screenWidth, height: 150}}
                               resizeMode="stretch"
                               source={{uri: ''}}>
                        </Image>
                    </View>
                    <View>
                        <Image style={{width: screenWidth, height: 150}}
                               resizeMode="stretch"
                               source={{uri: ''}}>
                        </Image>
                    </View>
                </Swiper>
            </View>
        );
    }

}


const styles = StyleSheet.create({
    dotStyle: {
        width: 22,
        height: 3,
        backgroundColor: '#fff',
        opacity: 0.4,
        borderRadius: 0,
    },
    activeDotStyle: {
        width: 22,
        height: 3,
        backgroundColor: '#fff',
        borderRadius: 0,
    },
    lunbotu: {
        height: 120,
        backgroundColor: '#222222'
    },

});


未完待续

相关标签: RN