react-native - 滚动不适用于 ScrollView 和绝对定位组件
问题描述
我有一个滚动视图和一个具有绝对位置的组件。scrollView 根本不滚动。看看代码:https ://snack.expo.io/@codebyte99/overlap-test
<ScrollView contentContainerStyle={{ flex: 1 }}>
<View style={styles.container}>
<Image
source={{
uri: 'https://facebook.github.io/react/logo-og.png',
cache: 'only-if-cached',
}}
style={{width: 400, height: 100}}
/>
<View style={styles.overlap}>
<Text>Event1</Text>
<Text>Event2</Text>
<Text>Event3</Text>
<Text>Event4</Text>
<Text>Event5</Text>
<Text>Event6</Text>
<Text>Event7</Text>
<View style={{ backgroundColor: 'orange', height: 800, width: 500 }}/>
<View style={{ backgroundColor: 'green', height: 800, width: 500 }}/>
</View>
</View>
</ScrollView>
const styles = StyleSheet.create({
container: {
flex: 1,
alignItems: 'center',
paddingTop: Constants.statusBarHeight,
backgroundColor: '#ecf0f1',
padding: 8,
},
overlap: {
width: 300,
backgroundColor: 'red',
borderColor: 'red',
borderWidth: 1,
position: 'absolute',
top: 80,
zIndex: 9999,
overflow: 'visible'
},
});
如果在scrollView中没有使用flex,绝对定位的组件是不完全可见的,如果使用了,则滚动不起作用。
解决方案
您是否尝试更改flex: 1
为flexGrow: 1
in contentContainerStyle
。
推荐阅读
- android - 改造预期为 BEGIN_OBJECT,但为 STRING
- ios - 是否可以制作包含 SwiftUI 的 Swift 项目模板?
- android - 如何将数据从 Android 中的数据报套接字发送到 Node js 服务器?
- php - 如何在 Laravel 中从 json 索引计数
- node.js - 在 Vagrant 框中连接 Angular 到 Node/express
- python - 单链表 Python 头部和尾部
- java - 首选项屏幕中的自定义列表首选项对话框布局,带有自定义列表项
- maven - 如何在idea中使用maven而不是iml运行应用程序
- c++ - std::async 参数太多
- c - 为什么转义字符 \b 在前几行不起作用?