无法将按钮对齐屏幕左下角 - 反应本地
问题描述:
我想将我的按钮放置在屏幕的左下角。我曾尝试使用bottom: 0
和left: 0
,但那没有做任何事情。我研究了一下,发现我需要设置position: 'absolute'
。但是,当我这样做时,我的按钮完全消失。无法将按钮对齐屏幕左下角 - 反应本地
如何通过按钮定位到屏幕左下角?
这里是我的代码:确定自己的位置absolute
当LY
import React, { Component } from 'react';
import { Button,Alert, TouchableOpacity,Image } from 'react-native'
import {
AppRegistry,
StyleSheet,
Text,
View,
} from 'react-native';
class Project extends Component {
render() {
return (
<View style={{backgroundColor: '#375D81', flex: 1}}>
<View style = {styles.container}>
<TouchableOpacity style = {styles.buttonText} onPress={() => { Alert.alert('You tapped the button!')}}>
<Text>
Button
</Text>
</TouchableOpacity>
</View>
</View>
);
}
}
const styles = StyleSheet.create({
main: {
backgroundColor: 'blue'
},
container: {
alignItems: 'center',
},
buttonText: {
borderWidth: 1,
padding: 25,
borderColor: 'black',
backgroundColor: '#C4D7ED',
borderRadius: 15,
bottom: 0,
left: 0,
width: 100,
height: 100,
position: 'absolute'
}
});
AppRegistry.registerComponent('Project',() => Project);
答
你忘了弯曲你的容器。添加:flex: 1
在那里,你都很好:
container: {
alignItems: 'center',
flex: 1
},
答
阵营本土元素从左上角的“渲染”。这意味着,当您定义bottom: 0
和left: 0
时,这是渲染您想要的项目水平,但垂直它将离开屏幕。切换到
position 'absolute',
bottom: 100,
left: 0,
这应该是你在找什么
它仍然导致相同的结果,一个空白的屏幕。即使对这些值进行实验也是如此。 –
我通过删除风格'容器'的视图找到了解决方案。如果有人可以回答为什么这个工程。 –