【问题标题】:Why scrollView is not working in vertical manner in my code?为什么 scrollView 在我的代码中不能以垂直方式工作?
【发布时间】:2019-02-05 07:33:58
【问题描述】:

在我的反应原生代码中,当我将 scrollView 水平放置时,我想以垂直方式滚动显示数组值而不是正常工作,但实际上我需要垂直方式。我尝试放置水平 false 请指导如何解决此问题

{this.state.status ? (

             <ScrollView horizontal pagingEnabled snapToInterval={300} directionalLockEnabled={true} >

          {
             this.state.newArr.map((item, index) => (

                <View  key = {item.id}>
                   <Text style={{color:"green",fontSize:14}} >{item.text}</Text>
                </View>

             ))
          }
       </ScrollView>
        <View style={{ paddingLeft: 5 }}>
                {this.state.status ? (
                  <View style={styles.SectionStyle2}>
                    <TextInput
                      placeholder="Type....."
                      ref="textInput"
                      value={this.state.inputValue}
                      maxLength={500}
                      fontSize={14}
                      multiline={false}
                      underlineColorAndroid="transparent"
                      style={{
                        flex: 1,
                        fontWeight: "bold",
                        paddingLeft: 5,
                        paddingRight: 0,

                        paddingTop: 0,
                        paddingBottom: 0
                      }}
                      blurOnSubmit={false}
                      autoFocus={true}
                      onChangeText={msg => this.setState({ msg })}
                    />

                    <TouchableOpacity
                      onPress={() =>
                        this.chatStart(this.doClear(this.viewChat()))
                      }
                    >
                      <Image
                        source={require("./SendMessage-35.png")}
                        style={{ height: 35, width: 35 }}
                      />
                    </TouchableOpacity>
                  </View>
                ) : null}
              </View>
            </View>
          ) : null}
        </View>

我希望数组数据可以垂直滚动。

【问题讨论】:

    标签: javascript android reactjs react-native


    【解决方案1】:

    看起来水平属性“自动”为真。也就是说,如果包含它,视图将水平滚动。希望这意味着默认值是垂直的,只需删除 horizontal 就足够了。 (我不确定,但无论如何这是我的印象,部分来自查看此资源): https://facebook.github.io/react-native/docs/using-a-scrollview

    【讨论】:

      【解决方案2】:

      刚刚添加了 ScrollView 的 nestedScrollEnabled 属性,然后 ScrollView 工作得很好。

      【讨论】:

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