簡體   English   中英

兩個按鈕共享反應原生的行

[英]Two buttons sharing a row in react-native

我有兩個看起來像這樣的按鈕

在此輸入圖像描述

這是代碼

render = () => (
    <Image
      source={require('../../images/login.jpg')}
      style={[AppStyles.containerCentered, AppStyles.container, styles.background]}
    >
      <Image
        source={require('../../images/logo.png')}
        style={[styles.logo]}
      />
      <Spacer size={200} />
      <View style={[AppStyles.row, AppStyles.paddingHorizontal]}>
        <View style={[AppStyles.flex1]}>
          <Button
            title={'Login'}
            icon={{ name: 'lock' }}
            onPress={Actions.login}
          />
        </View>
      </View>

      <Spacer size={10} />


      <View style={[AppStyles.row, AppStyles.paddingHorizontal]}>
        <View style={[AppStyles.flex1]}>
          <Button
            title={'Sign up'}
            backgroundColor={'#FB6567'}
            icon={{ name: 'face' }}
            onPress={Actions.signUp}
          />
        </View>
      </View>

    </Image>
  )

我希望按鈕占據一行並可能占用40% - 40%的空間,剩下的20%用於填充。 我怎么能讓他們占據一排?

您需要定義一個flexDirection設置為row的容器,並根據您想要填充的位置使用justifyContent

render() {
  return (
    <View style={styles.container}>
      <View style={styles.button} />
      <View style={styles.button} />
    </View>
  );
}

const styles = StyleSheet.create({
  container: {
    flex: 1,
    flexDirection: 'row',
    justifyContent: 'space-between'
  },
  button: {
    backgroundColor: 'green',
    width: '40%',
    height: 40
  }
});

更改space-betweenspace-around ,如果你想填充分發到邊了。 演示

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM