簡體   English   中英

為什么scrollView在我的代碼中不能以垂直方式工作?

[英]Why scrollView is not working in vertical manner in my code?

在我的反應本機代碼中,當我將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>

我預計數組數據應該可以垂直滾動。

看起來水平屬性“自動”為true。 也就是說,如果包含的話,視圖將水平滾動。 希望這意味着默認值為垂直,而僅刪除horizontal就足夠了。 (我不確定,但這仍然是我的印象,部分原因是查看此資源): https : //facebook.github.io/react-native/docs/using-a-scrollview

只需添加ScrollView的nestedScrollEnabled Prop,然后使ScrollView完美地工作即可。

暫無
暫無

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

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