在React Native中横向排列图像 – Flex不起作用。

huangapple go评论65阅读模式
英文:

Arrange images in Horizontal - React Native - Flex not working

问题

我在这里尝试将图像水平排列在一起,然后将其转换为滑块。但在我将它们设置成一排之前,这并没有发生。需要帮助。
以下是代码:

样式 -

 profileImgContainer: {
    
    marginLeft: 8,
    height: 80,
    width: 80,
    borderRadius: 40,
    overflow: 'hidden',
  },
  profileImg: {
    flex: 1,
    flexDirection: 'row',
    height: 80,
    width: 80,
    borderRadius: 40,
  },

组件 -

<FlatList
               data={this.state.Products}
               keyExtractor={(item, index) => index.toString()} 
               renderItem= { ({item}) => (
                <TouchableHighlight
                style={[styles.profileImgContainer, { borderColor: 'green', borderWidth:1 }]}>
                <Image source={{ uri: item.url }} style={styles.profileImg} />
                </TouchableHighlight>
               )}
               />;

它目前显示如下。

在React Native中横向排列图像 – Flex不起作用。

英文:

I am here trying to arrange the images horizontally next to each other and later convert it to the slider. But until I set them in a row, which is not happening for me. Need help
Below is the code:

Style -

 profileImgContainer: {
    
    marginLeft: 8,
    height: 80,
    width: 80,
    borderRadius: 40,
    overflow: &#39;hidden&#39;,
  },
  profileImg: {
    flex: 1,
    flexDirection: &#39;row&#39;,
    height: 80,
    width: 80,
    borderRadius: 40,
  },

Component -

&lt;FlatList
               data={this.state.Products}
               keyExtractor={(item, index) =&gt; index.toString()} 
               renderItem= { ({item}) =&gt; (
                &lt;TouchableHighlight
                style={[styles.profileImgContainer, { borderColor: &#39;green&#39;, borderWidth:1 }]}&gt;
                &lt;Image source={{ uri: item.url }} style={styles.profileImg} /&gt;
                &lt;/TouchableHighlight&gt;
               )}
               /&gt;

It is currently appearing like this.

在React Native中横向排列图像 – Flex不起作用。

答案1

得分: 3

尝试类似以下方式:

<FlatList
    horizontal
    data={this.props.data}
    extraData={this.state}
    keyExtractor={this._keyExtractor}
    renderItem={this._renderItem}
/>

只需将此属性添加到您的FlatList中:

horizontal
英文:

Try something like this :

&lt;FlatList
    horizontal
    data={this.props.data}
    extraData={this.state}
    keyExtractor={this._keyExtractor}
    renderItem={this._renderItem}
/&gt;

Just add this property to your flatlist :

horizontal

答案2

得分: 2

你缺少了FlatList的horizontal属性,只需将你的代码替换为以下内容:

<FlatList
    data={this.props.data}
    extraData={this.state}
    keyExtractor={this._keyExtractor}
    renderItem={this._renderItem}
    horizontal
/>

希望对你有所帮助。如果有疑问,请随时提问。

英文:

You are missing the horizontal property of Flat list , Just replace your code with this :

&lt;FlatList
    data={this.props.data}
    extraData={this.state}
    keyExtractor={this._keyExtractor}
    renderItem={this._renderItem}
    horizontal
/&gt;

Hope it helps .feel free for doubts

huangapple
  • 本文由 发表于 2020年1月3日 20:47:55
  • 转载请务必保留本文链接:https://go.coder-hub.com/59578925.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定