如何在React Native中将按钮对齐到屏幕底部?

3
我是一名有用的助手,可以为您翻译文本。

我正在使用来自React Native Paper库的FAB(https://callstack.github.io/react-native-paper/fab.html#icon)。 我想将按钮对齐到底部,但它与textInput字段重叠,如何将其放置在该textInput下方?请参见下面的屏幕截图。

代码:

//Inside return
    <ScrollView>

                    <Text style={styles.title}>Add a Lead</Text>

                    <View style={styles.inputContainer}>
                        <Image source={require('../../assets/images/name.png')} style={{
                            marginTop: 15, width: 32, height: 32, resizeMode: 'contain'}}/>
                        <TextInput
                            placeholder='Name'
                            value={this.state.name}
                            style={styles.input}
                            onChangeText={ name => this.setState({name})}
                            error={this.state.nameError}
                        />
                    </View>
                    <HelperText type="error" visible={this.state.emailError}>
                        {this.state.emailError}
                    </HelperText>

            Similarly other items for phone email etc....

            <View style={{marginTop: 20, flex: 1, flexDirection: 'row'}}>
                        <Image source={require('../../assets/images/comment.png')} style={{
                            marginTop: 20, width: 32, height: 32, resizeMode: 'contain'}}/>
                        <Text style={{marginTop: 25, marginLeft: 15}}>Comment</Text>
                    </View> 

                    <View>
                        <TextInput
                            style={{height: 65, marginTop: 15, borderColor: 'gray', borderWidth: 1}}
                            onChangeText={(comment) => this.setState({comment})}
                            value={this.state.comment}
                            error={this.state.commentError}
                            multiline = {true}
                            numberOfLines = {4}
                        />
                    </View>
            <FAB
                    style={styles.fab}
                    small
                    icon="arrow_forward"
                    onPress={this.handleCreateNewLead}
                />
    </ScrollView>

CSS:

fab: {
        position: 'absolute',
        margin: 16,
        right: 0,
        bottom: -20,
    },

截图:

当前的样子:

enter image description here

2个回答

3

对于你放置了问号图标的文本框(textarea),已添加position:relative。

<TextInput style={{height: 65, marginTop: 15, borderColor: 'gray', borderWidth: 1, position: relative}}

并更改浮动操作按钮(fab component)的以下样式

fab: {
        position: 'absolute',
        margin: 16,
        right: 10,
        bottom: 10,
    }

也许它会起作用。


1

您需要使用View组件包装TextField和FAB组件;

<View style={styles.container}>
    <TextInput
        style={styles.textField}
        onChangeText={(comment) => this.setState({comment})}
        value={this.state.comment}
        error={this.state.commentError}
        multiline={true}
        numberOfLines={4}
    />
    <FAB
        style={styles.fab}
        small
        icon="arrow_forward"
        onPress={this.handleCreateNewLead}
    />
</View>

并使用以下样式更改您的样式;

const styles={
    container:{
        flexDirection:"row",
        alignItems:"center",
        marginTop: 15
    },
    textField:{
        flex:1,
        height: 65,
        borderColor: 'gray',
        borderWidth: 1
    },
    fab: {
        position:"absolute",
        right:0,
    },
};

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接