代码之家  ›  专栏  ›  技术社区  ›  fun joker

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

  •  0
  • fun joker  · 技术社区  · 5 年前

    我用的是Fab( https://callstack.github.io/react-native-paper/fab.html#icon )来自React Native Paper Library。我想在底部对齐按钮,但它与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 回复  |  直到 5 年前
        1
  •  1
  •   Balaji731    5 年前

    对于文本区域(您放置了哪个?图标)添加位置:相对。

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

    并更改FAB组件的以下样式

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

    希望它能奏效。

        2
  •  1
  •   sdkcy    5 年前

    您需要用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,
        },
    };