示例
import React, { Component } from 'react';
import {View,ScrollView,StyleSheet ,Dimensions,Text} from 'react-native';
const {width, height} = Dimensions.get('window');
export class pageComponent extends Component {
render() {
return (
<ScrollView
horizontal={true}
showsHorizontalScrollIndicator={false}
pagingEnabled={true}
>
{this.renderChildView()}
</ScrollView>
);
}
renderChildView(){
let childs = [];
let colors = ['#00ff00', '#ff00ff', '#0000ff', '#ffffff', '#000000'];
for(let i=0; i<5; i++){
let viewStyle={
backgroundColor:colors[i],
width:width,
height:300,
justifyContent: 'center',
alignItems: 'center',
};
let textStyle={
fontSize:20,
textAlign:'center',
color:'red'
}
childs.push(
<View key={i} style={viewStyle}>
<Text style={textStyle}>{colors[i]}</Text>
</View>
);
}
return childs;
}
}