简体   繁体   English

flex with textinput 在我的反应本机应用程序中不起作用

[英]flex with textinput not working in my react native app

I want to extend the TextInput to the entire screen and not set a definite width.我想将 TextInput 扩展到整个屏幕,而不是设置明确的宽度。
To do that I know we have to set "flex:1"为此,我知道我们必须设置“flex:1”
But it doesn't seem to work at all.但它似乎根本不起作用。 What is wrong here??这里有什么问题?? I want the TextInput to be stretched with the Button next to it.我希望 TextInput 使用旁边的 Button 进行拉伸。

 <View style={{flex: 1, alignItems: 'stretch' , flexDirection: 'row'}}>

        <TextInput value="nil" style={{ backgroundColor:"grey", height: 40}} textAlign='center'/>
        <Button title="V" onPress={()=>{this.dropList()}} />

        </View>

在此处输入图像描述

I want something like this.我想要这样的东西。 How do I get this???我怎么得到这个???

在此处输入图像描述

You can use CSS Grid in your View , adding grid-template-columns for the columns width, like:您可以在View中使用 CSS Grid ,为列宽添加grid-template-columns ,例如:

display: grid;
grid-template-columns: 1fr 3rem;
width: 100%;

With inline styles (not recommended at all):使用内联 styles(完全不推荐):

{{ display: 'grid'; gridTemplateColumns: '1fr 3rem'; width: '100%' }}

You are putting the flex property on the parent whereas it needs to be applied on the TextInput itself.您将flex属性放在父级上,而它需要应用于TextInput本身。

Bonus : You don't need to set flexDirection to row because that's the default.奖励:您不需要将flexDirection设置为row因为这是默认设置。

Here's a pure HTML, CSS example to show what I mean.这是一个纯 HTML、CSS 示例来说明我的意思。

 .view { display: flex; }.view input { flex: 1; }
 <div class='view'> <input/> <button>Click Me</button> </div>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM