【发布时间】:2019-06-23 05:09:18
【问题描述】:
我正在使用RN 0.59.8 开发应用程序。我正在尝试使用ScrollView 水平创建可滚动视图。这是我的代码的基础(抱歉我不能分享更多细节):
import React, { Component, Fragment } from 'react';
import {
ScrollView,
} from 'react-native';
import {
Container,
Content,
} from 'native-base';
import { Grid, Row } from 'react-native-easy-grid';
import ChildComponent from './ChildComponent';
class MyComponent extends Component {
render() {
const {
data,
} = this.props;
return (
<Container>
<Content>
<Grid>
<Row>
<ScrollView
horizontal
contentContainerStyle={{
flex: 1, flexGrow: 1, flexDirection: 'row',
}}
>
{
data.map((item, index) => {
const order = index;
return (
<Fragment key={order}>
{
<ChildComponent />
}
</Fragment>
);
})
}
</ScrollView>
</Row>
</Grid>
</Content>
</Container>
);
}
}
export default MyComponent;
当前行为:
- 如果
contentContainerStyle={{ flex: 1, flexGrow: 1, flexDirection: 'row' }},第二个数据不出现 - 如果
contentContainerStyle={{ flex: 1, flexGrow: 1, flexDirection: 'column' }},第二条数据垂直出现 - 如果
contentContainerStyle={{ flexDirection: 'row' }},第二个数据不出现,内容比屏幕宽度宽
我的反对是:
- 我想让它水平滚动
- 每个数据都适合屏幕宽度
任何帮助都会非常有帮助。谢谢!!!
【问题讨论】:
-
所以你只是想让这个scrollView的每个孩子都成为屏幕的宽度?如果是这样,您可以更改子项的呈现方式,为它们添加样式并将它们的宽度设置为 '100%'
-
@mAhMoUdDaFeR 我已经尝试过了,但是如果我将 flexDirection 设置为“行”,问题仍然是第二个数据不会出现在任何地方,但是如果我将 flexDirection 设置为“列”,则所有数据都会垂直显示
标签: react-native scrollview horizontalscrollview