【问题标题】:React Native parent view size is changing when adding a child view添加子视图时,React Native 父视图大小正在发生变化
【发布时间】:2021-01-07 10:09:39
【问题描述】:

我的应用中有语言选择设置。如下所示,当我选择另一种语言时,所选语言的行高会增加一点。我想保持它固定,并且选择一种语言不应该对行高产生影响。我怎样才能做到这一点?

      <FlatList
        data={availableLanguages}
        ItemSeparatorComponent={this.renderSeparator}
        renderItem={({ item }) => {
          return (
            <TouchableOpacity onPress={() => this.onChangeLang(item)}>
              <View style={styles.flatlistItem} >
                <Text style={styles.languageListitem} >{t('settings:' + item)}</Text>
                {appLanguage === item ? <View style={styles.listIconRightEnd}><CheckActiveLightMode width={25} /></View> : null}
              </View>
            </TouchableOpacity>
          )
        }}
        keyExtractor={(item, index) => index}
      />

样式:

  flatlistItem: {
    margin: 4,
    paddingLeft: 10,
    paddingVertical: 7,
    backgroundColor: '#FFF',
    width: '100%',
    flex: 1,
    alignSelf: 'center',
    flexDirection: 'row',
    borderRadius: 0,
  },

  languageListitem: {
    color: 'rgb(48,49,147)',
    fontSize: 16,
    paddingLeft: 10,
    flex: 1,
  },

  listIconRightEnd: {
    paddingRight: 20,
  },

【问题讨论】:

    标签: javascript css react-native


    【解决方案1】:

    用 maxHeight 解决:

     listIconRightEnd: {
       paddingRight: 20,
       maxHeight: 10,
     },
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多