React-Native:两个视图之间无法解释的空间(一条白线)

2024-02-23

我有两个视图,一个堆叠在另一个之上。

模拟器中的截图:

What I see on my phone: enter image description here

从屏幕上可以看出,模拟器版本很好,但我有一个两个视图之间的白线在我的手机上。代码如下:

import React, { Component } from 'react';

import {
  Text,
  View,
  StyleSheet,
} from 'react-native';

class FlightSearch extends Component {

  render() {

    return (
      <View style={styles.pageRoot}>

        <View style={styles.navSection}></View>

        <View style={styles.searchSection}>

          <View style={styles.locationSection}></View>

          <View style={styles.searchParametersSection}></View>

        </View>

      </View>
    );
  }

}


const styles = StyleSheet.create({
  pageRoot: {
    flex: 1,
    flexDirection: 'column',
  },
  navSection: {
    backgroundColor: '#368ec7',
    flex: 25,
    alignSelf: 'stretch'
  },
  searchSection: {
    flex: 75,
    alignSelf: 'stretch',
  },
  locationSection: {
    flex: 30,
    backgroundColor: '#276fa3',
    padding: 10,
    paddingLeft: 20,
    paddingRight: 20,
    borderBottomWidth: 1,
    borderBottomColor: '#205e8c'
  },
  searchParametersSection : {
    flex: 70,
    backgroundColor: 'rgba(41,123,184,1)',
    borderTopWidth: 1,
    borderTopColor: 'rgba(69, 140, 194, 0.7)',
    flexDirection: 'column'
  }
});

export default FlightSearch;

我在滚动视图中遇到了同样的问题,其中很少有图像水平放置,它们之间没有任何空间。在 iOS 上工作时我没有遇到任何问题,但是当我切换到 Android 时,那些白线就会弹出,并且在某些滚动位置消失。我使用的 hack 是添加一个marginRight: -1(水平图像)。

用户不会注意到差异,但这样您就可以解决问题。

return (
      <ScrollView ref='sr' style={styles.container} horizontal={true}>
        <Image source={im1} style={{height: h, width: 400, resizeMode: 'stretch', marginRight: -1}} />
        <Image source={im2} style={{height: h, width: 400, resizeMode: 'stretch', marginRight: -1}} />
        <Image source={im3} style={{height: h, width: 400, resizeMode: 'stretch', marginRight: -1}} />
        <Image source={im4} style={{height: h, width: 400, resizeMode: 'stretch', marginRight: -1}} />
        <Image source={im5} style={{height: h, width: 400, resizeMode: 'stretch', marginRight: -1}} />
        <Image source={im6} style={{height: h, width: 400, resizeMode: 'stretch', marginRight: -1}} />
      </ScrollView>
    )
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

React-Native:两个视图之间无法解释的空间(一条白线) 的相关文章

随机推荐