javascript - React 原生滚动子栏目
问题描述
我有这样的看法
<View style={styles.columnView}>
<View style={[styles.columnButtonItem, styles.columnC]}><Text></Text></View>
<View style={[styles.columnButtonItem, styles.columnA]}><Text></Text></View>
<View style={[styles.columnButtonItem, styles.columnB]}><Text></Text></View>
<View style={[styles.columnButtonItem, styles.columnE]}><Text>{value}</Text></View>
<View style={[styles.columnButtonItem, styles.columnAs]}><Text></Text></View>
<View style={[styles.columnButtonItem, styles.columnT]}><Text></Text></View>
</View>
迭代后,我组成一个这样的表:
有没有办法在单列上添加 ScroolView?例如,我只想在 columnE 上启用滚动。显然,当我滚动 columnE 时,我想滚动所有表格。
谢谢
解决方案
绝对定位视图
如果您知道列的宽度,那么您可以使用与底层重叠的绝对定位的视图ScrollView
,它们将停止对ScrollView
. 这意味着它只会在绝对定位视图未覆盖的部分上滚动。
所以你可以做这样的事情
render() {
// set these widths to be the size before row E and the size after row E
let leftWidth = '33%';
let rightWidth = '33%';
return (
<View style={{flex: 1}}>
<ScrollView style={{flex: 1}}>
// items for the scroll view go here
</ScrollView>
<View style={{position:'absolute', top:0, left: 0, bottom: 0, width: leftWidth}} />
<View style={{position:'absolute', top:0, right: 0, bottom: 0, width: rightWidth}} />
</View>
)
}
小吃
这是一个展示此实现的小吃。我backgroundColor
在绝对定位视图上设置了一个,以便您可以清楚地看到它们。
https://snack.expo.io/@andypandy/partial-scrollview
警告
此解决方案的主要问题是您将无法触摸绝对定位视图下方的任何内容。您可以通过使用每个手势View
捕获触摸然后将它们映射到ScrollView
.
推荐阅读
- java - 为什么 liferay 加载我的 JKS 文件不一致?
- azure - 如何阻止用户直接在 Azure DevOps 中从功能分支创建 PR(拉取请求)到 Main 分支
- docker - 如何在 kubernetes 中传递参数以启动 rq-worker 容器
- python - 为什么 python 广播器在配置 PostgreSQL 后端时收不到消息?
- javascript - 将 Javascript 应用程序移植到 iOS/Android Flutter
- javascript - 如何通过唯一 ID 在 ReactJs 中呈现 API 数据?
- android - 颤振中的工作日选择
- flutter - 如何使文本在颤动中填充宽度?
- android - 如何从点开始显示 xAxis 的标签?
- python - Django:如何使用 Prefetch 对象“加入”两个查询集?