我试图实现React Native Elements的输入,这是蓝色的。我想使输入在红色视图中具有完整宽度。 所以我做到了
宽度:“ 100%”,marginHorizontal:0,填充:0,以及alignItems:“ stretch”。
但是它们都不起作用。问题是什么? 这是屏幕截图
这是对应的代码
<View style = {styles.campusInputView}>
<Input
containerStyle = {styles.campusInputContainer}
inputStyle = {styles.campusInput}
placeholder = 'KAIST'
editable = {false}
/>
</View>
具有样式
campusInputView: {
borderWidth: 1,
borderColor: 'red',
position: 'absolute',
top: height * 100 / 640,
left: width * 45 / 360,
width: width * 270 / 360,
},
campusInputContainer: {
borderWidth: 1,
borderColor: 'green',
alignItems: 'stretch',
},
campusInput: {
borderWidth: 1,
borderColor: 'blue',
flex: 1,
fontFamily: 'NanumSquareB',
fontSize: 20,
paddingVertical: 0,
},
答案 0 :(得分:1)
将paddingHorizontal
中的containerStyle
覆盖为0
将使输入全角。
仅将padding
覆盖为0
是不够的。
import { Input } from 'react-native-elements'
<Input
containerStyle = {{ paddingHorizontal: 0 }}
// other settings
/>
答案 1 :(得分:0)
您想要的width
是100%
。然后将border
的颜色设置为red
。
import React, { Component } from 'react';
import { Text, View, StyleSheet, FlatList } from 'react-native';
import { Input } from 'react-native-elements';
export default class App extends Component {
render() {
return (
<View style = {styles.campusInputView}>
<Input
containerStyle = {styles.campusInputContainer}
inputStyle = {styles.campusInput}
placeholder = 'KAIST'
editable = {false}
/>
</View>
);
}
}
const styles = StyleSheet.create({
campusInputView: {
flex:1,
justifyContent:"center",
alignItems:"center"
},
campusInputContainer: {
borderWidth: 1,
borderColor: 'red',
alignItems: 'stretch',
},
campusInput: {
flex: 1,
fontFamily: 'NanumSquareB',
fontSize: 20,
paddingVertical: 0,
},
});
答案 2 :(得分:0)
您应将paddingHorizontal: 0
添加到campusInputContainer
campusInputContainer: {
borderWidth: 1,
borderColor: 'green',
alignItems: 'stretch',
paddingHorizontal: 0
},