user12541823
user12541823

Reputation:

Add 2 buttons in the same line

How can I use Native Base buttons in a way that they both appear to be in the same line? Currently, the second button is on the right as it should be, but it appears a bit lower than the first button. How can I fix this?

          <View style={scaledAvailableTripsStyles.buttonView}>
          <Button
          rounded
          style={scaledAvailableTripsStyles.button}>
          <Text style={scaledAvailableTripsStyles.text}>Button 1</Text>
        </Button>
        <View style={scaledAvailableTripsStyles.rightButtonView}>
        <Button
          rounded
          style={scaledAvailableTripsStyles.buttonBlack}>
          <Text style={scaledAvailableTripsStyles.text}>Button 2</Text>
        </Button>
        </View>
        </View>

Styling:

button: {
    width: moderateScale(170),
    height: moderateScale(40),
    backgroundColor: '#31C283',
    justifyContent: 'center',

  },
  buttonBlack: {
    width: moderateScale(170),
    height: moderateScale(40),
    backgroundColor: '#2E3331',
    justifyContent: 'center',

  },
  text: {
    fontSize: moderateScale(14, 0.7),
  },
  searchField: {
    width: 300,
  },
  buttonView: {
    paddingTop: 450,
  },
  rightButtonView: {
    paddingLeft: 200,
  }

Edit: Got this after adding flexDirection. How can I make some space between the two buttons?

enter image description here

Upvotes: 0

Views: 2754

Answers (3)

Tawhid Monowar
Tawhid Monowar

Reputation: 162

HTML Code

<div class="btnDiv">
    <button class="regBtn" type="submit">Register</button>
    <button class="regBtn" type="submit">Login</button>
</div>

CSS Code

.btnDiv{
    position: relative;
}
.regBtn{
    padding: 10px;
    margin-top: 20px;
    width: 49%;
    background-color: cadetblue;
    border-radius: 3px;
    border: none;
    color: white;
    font-weight: bold;
    display: inline-block;
}

Upvotes: 0

Mahdi N
Mahdi N

Reputation: 2178

Generally when you want 2 component in the same line you could wrap them with a View and add flexDirection: 'row' to style.

So you could add flexDirection: 'row' and justifyContent: 'space-between'(to space children components) to buttonView object in the styles

Upvotes: 1

Sohan
Sohan

Reputation: 588

      <View style={styles.ButtonContainer}}>
       <View style={scaledAvailableTripsStyles.buttonView}>
            <Button
               rounded
               style={scaledAvailableTripsStyles.button}>
               <Text style={scaledAvailableTripsStyles.text}>Button 1</Text>
            </Button>
      </View>
      <View style={scaledAvailableTripsStyles.rightButtonView}>
            <Button
               rounded
               style={scaledAvailableTripsStyles.buttonBlack}>
               <Text style={scaledAvailableTripsStyles.text}>Button 2</Text>
            </Button>
      </View>
    </View>

Styling:

ButtonContainer: {
   flexDirection: 'row',
   alignItems: 'center' //This will center you button
}

Upvotes: 0

Related Questions