react-native - 问题定位元素到底部
问题描述
我使用本机基础作为我的应用程序模板,并且我一直在尝试仅使用 flex 将两个按钮元素放置在页脚上方。这是按钮当前的位置。
我尝试做 justifyContent: flex-end / space-between 但按钮仍然远离页脚。
<Container>
<Header>
<MainHeader />
</Header>
<Content>
<View style={{flex: 1, justifyContent: 'center'}} >
<View style={{ borderBottomColor: 'black', borderBottomWidth: 1, height: 50 }}>
<View style={{ flexDirection: 'row' }}>
<View style={{ flex: 1, alignSelf: 'center' }}>
<Text>Name</Text>
</View>
<View style={{ flex: 1, alignSelf: 'center' }}>
<Text>Sales</Text>
</View>
<View style={{ flex: 1, alignSelf: 'center' }}>
<Text>Commission</Text>
</View>
<View style={{ flex: 1, alignSelf: 'center' }}>
<Text>Payout</Text>
</View>
<View style={{ flex: 1, alignSelf: 'center' }}>
<Text>Profit</Text>
</View>
</View>
</View>
{this.renderRow()}
<View style={{ flexDirection: 'column', justifyContent: 'space-between' }} >
<View style={{ flexDirection: 'row', alignSelf: 'stretch', height: 50, justifyContent: 'space-between' }} >
<View style={{flex:1, alignSelf: 'center'}}>
<Button onPress={() => this.share(this.state.response)} title="Share"></Button>
</View>
<View style={{flex:1, alignSelf: 'center'}}>
<Button onPress={() => this.share(this.state.response)} title="Share"></Button>
</View>
</View>
</View>
</View>
</Content>
<Footer>
<MainFooter />
</Footer>
</Container>
我希望共享按钮位于页脚上方的页面底部。
解决方案
原因基本上是因为一切都在里面content
,基本上是一个滚动视图。您不能将某些内容发送到滚动视图的末尾,因为它是父级。
您可以contentContainerStyle
从原生基础访问内容的道具,然后将其样式设置为 justifyConent 和 alignItens -> flex-end。
我希望它会奏效。
推荐阅读
- python - 为什么 `value_counts` 函数会忽略特定值?
- html - 我可以在没有 php 和数据库的服务器上托管 HTML 站点吗?
- node.js - Express.js http响应是否默认返回一个promise
- python - 我如何在 django 中使用模型对象预先填写表单字段
- android - 如何在android框架[AOSP] java文件(不是Android Studio或Java IDE)中使用像jsoup库这样的外部jar
- c# - 通用参数多个 where 子句问题
- javascript - 将子集合添加到 Firestore
- rust - 如何避免 filter_map() 在 Rust 中给出错误“返回引用当前函数拥有的数据的值”?
- json - 反序列化 json 以查找映射 Android Kotlin 的对象
- python - 停止通过 SSH 运行的远程脚本