Javascript React Native-如何设置ScrollView内的视图宽度以适合?
我的水平滚动视图中有多个视图。如何设置它们,使每个视图都具有与ScrollView相同的精确尺寸Javascript React Native-如何设置ScrollView内的视图宽度以适合?,javascript,android,reactjs,react-native,Javascript,Android,Reactjs,React Native,我的水平滚动视图中有多个视图。如何设置它们,使每个视图都具有与ScrollView相同的精确尺寸 我想使用分页并在滑动时转到ScrollView中的下一个视图。我尝试过使用宽度:“100%”,但它不起作用,因为ScrollView没有固定的尺寸,但这基本上就是我想对其中的视图所做的。这是我的密码: export default class HorizontalScrollView extends Component { render () { screenWidth = "100
我想使用分页并在滑动时转到ScrollView中的下一个视图。我尝试过使用宽度:“100%”,但它不起作用,因为ScrollView没有固定的尺寸,但这基本上就是我想对其中的视图所做的。这是我的密码:
export default class HorizontalScrollView extends Component {
render () {
screenWidth = "100%"
return (
<ScrollView
contentContainerStyle={styles.scrollable}
horizontal={true}
snapToInterval={screenWidth}
decelerationRate={"fast"}
>
<View style={StyleSheet.compose(styles.insideContainer, {"width" : screenWidth, "backgroundColor" : "red"})}>
<Text>Screen 1</Text>
</View>
<View style={StyleSheet.compose(styles.insideContainer, {"width" : screenWidth, "backgroundColor" : "blue"})}>
<Text>Screen 3</Text>
</View>
<View style={StyleSheet.compose(styles.insideContainer, {"width" : screenWidth, "backgroundColor" : "green"})}>
<Text>Screen 2</Text>
</View>
</
另外,我正在使用安卓三星Galaxy M30来测试这一点任何帮助或解释都将不胜感激
多谢各位 如果滚动视图是屏幕的宽度,则可以将内部的每个视图的宽度设置为
Dimensions.get(“screen”).width
然后将ScrollView的PaginEnabled属性设置为true,您应该有一个带有全宽子视图的分页滚动条 根据您的代码,使用这些样式来完成您想要的
屏幕1
屏幕2
屏幕3
Dimensions.get(“screen”).width