最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - React native Elements Input full width - Stack Overflow

programmeradmin4浏览0评论

I was trying to implement the Input from React Native Elements, which is the blue one. I want to make the Input have full width within the red view. So I did

width: '100%', marginHorizontal: 0, padding: 0, and alignItems: 'stretch' independently.

But none of them didn't work. What is the problem? This is the screenshot of the screen

And this is the corresponding code

    <View style = {styles.campusInputView}>
      <Input
        containerStyle = {styles.campusInputContainer}
        inputStyle = {styles.campusInput}
        placeholder = 'KAIST'
        editable = {false}
      />
    </View>

with the style

  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,
  },

I was trying to implement the Input from React Native Elements, which is the blue one. I want to make the Input have full width within the red view. So I did

width: '100%', marginHorizontal: 0, padding: 0, and alignItems: 'stretch' independently.

But none of them didn't work. What is the problem? This is the screenshot of the screen

And this is the corresponding code

    <View style = {styles.campusInputView}>
      <Input
        containerStyle = {styles.campusInputContainer}
        inputStyle = {styles.campusInput}
        placeholder = 'KAIST'
        editable = {false}
      />
    </View>

with the style

  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,
  },
Share Improve this question edited Aug 13, 2019 at 13:48 Kareem Dabbeet 3,9943 gold badges18 silver badges35 bronze badges asked Aug 13, 2019 at 13:36 TonyWildTonyWild 411 gold badge1 silver badge2 bronze badges 0
Add a ment  | 

3 Answers 3

Reset to default 12

Overwriting paddingHorizontal of containerStyle as 0 makes the input full width. Overwriting only padding as 0 is not enough.

import { Input } from 'react-native-elements'

<Input
  containerStyle = {{ paddingHorizontal: 0 }}
  // other settings
/>

You should add paddingHorizontal: 0 to campusInputContainer

campusInputContainer: {
  borderWidth: 1,
  borderColor: 'green',
  alignItems: 'stretch',
  paddingHorizontal: 0
},

The width you want is 100%. And I set the color of the border to 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,
  },
});

发布评论

评论列表(0)

  1. 暂无评论