【发布时间】:2020-12-28 00:58:53
【问题描述】:
我正在尝试在我的社交网络应用上构建用户的个人资料屏幕。我想要的方式是屏幕的顶部 1/3 是用户个人资料信息,底部 2/3 是所有用户帖子的平面列表。目前,我有所有的工作逻辑。这是应用程序的屏幕截图:
如您所见,用户个人资料信息显示在顶部,用户的帖子历史记录正确显示在下面的平面列表中。但是,平面列表将用户个人资料信息“向上”推送到屏幕上。
这是配置文件的代码:
class Profile extends React.Component {
constructor(props) {
super(props)
this.state = {
user: this.props.user
}
}
goToSettings = () => {
this.props.navigation.navigate('Settings')
}
render() {
return (
<View style={styles.container}>
<View style={{ flexDirection: "row", padding: 20 }}>
<Text style = {styles.subheader}> {this.state.user.username} </Text> <------The username is being pushed up, where only the bottom half of it is visible
<TouchableOpacity
onPress={this.goToSettings}>
<Ionicons name="ios-settings" size={24} color="black" />
</TouchableOpacity>
</View>
<View style = {styles.lineStyle} />
<View style={{ flexDirection: "row" }}>
<ProfilePic/>
<ProfileStats/>
</View>
<View style = {styles.lineStyle} />
<ProfileBio />
<View style = {styles.lineStyle} />
<View style={{ flexDirection: "row", alignItems: 'center', justifyContent: 'center' }}>
<CurrentUserPostFeed navigation = {this.props.navigation} /> <------ This is the flat list. It is pushing up the views & other components that are above it.
</View>
</View>
)
}
}
我希望用户个人资料信息的位置保持不变,占据屏幕顶部 1/3,而用户可以滚动浏览仅占底部 2/3 的平面列表屏幕的
但是,我不确定如何将个人资料信息“锁定”到位,无论帖子的平面列表有多大/多小,它都始终显示在个人资料屏幕的顶部 1/3 中。有什么建议吗?
编辑:似乎平面列表单元格中的边距/填充导致了我的问题。当我添加 marginTop 或 paddingTop 时,有没有办法可以防止 flatlist 容器将其上方的元素“向上”推?
【问题讨论】:
标签: react-native