Android:包含textInput不滚动的ScrollView

时间:2017-05-21 05:06:26

标签: android react-native scrollview textinput

我有一个包含太多textInput的scrollView。一切正常,直到我将textAlign: 'right'添加到TextInput样式。之后,ScrollView无法响应滚动。这个问题刚出现在android中,在iOS中它按预期工作。我在snack.expo

中添加了一个简单的代码
  render() {
    let TextInput2 = (
      <TextInput
        style={{
          flex: 1,
          textAlign: 'right',
          height: 50
        }}
        placeholder="placeholder"
      />
    );
    return (
      <ScrollView>
        {TextInput2}
        {TextInput2}
        {TextInput2}
        {TextInput2}
        {TextInput2}
        {TextInput2}
        {TextInput2}
        {TextInput2}
        {TextInput2}
        {TextInput2}
        {TextInput2}
        {TextInput2}
        {TextInput2}
        {TextInput2}
      </ScrollView>
    );
  }

2 个答案:

答案 0 :(得分:1)

如果ScrollView中的项目过多,那么您应该考虑使用ListView。我有类似的问题。在滚动太多项目之后的某个时刻,ScrollView在Android中首先开始失败。我假设i-devices在渲染反应原生组件方面有更好的优化,这可以防止它们提前失败。

答案 1 :(得分:1)

我不确定为什么textAlign:'right'会导致这种情况,但我注意到ios和android TextInput之间存在很大差异。在Android上,如果TextInput框小于字体大小,它会在其内部创建一个可滚动的TextInput,从而阻止scrollview成为响应者。尝试增加每个TextInput的高度和宽度,以确保不是这种情况。