我正在开发一款React原生应用程序,它有一个用户化身组件,具有重叠效果:

enter image description here

我能够在iOS上运行它,因为它允许负边距,但当你在Android上使用负边距时,它会像这样剪辑最后一张图像:

enter image description here

以下是我正在使用的样式:

avatarContainer: {
    borderRadius: 20,
    width: 40,
    height: 40,
    marginRight: -11
},

avatar: {
    borderRadius: 20,
    width: 40,
    height: 40
},

avatarContainer是图像后面的白色圆圈,avatar是图像本身.

在这两种平台上实现理想造型的最佳方法是什么?

推荐答案

我已经try 了你的设置+flexbox,一切似乎都正常.

enter image description here

class App extends React.Component {
  render() {
    const { overlapContainer, avatarContainer, avatar} = styles;

    return (
        <View style={overlapContainer}>

          <View style={avatarContainer}>
            <Image style={avatar} source={{ uri: 'http://lorempixel.com/output/cats-q-c-100-100-3.jpg' }} />
          </View>

          <View style={avatarContainer}>
            <Image style={avatar} source={{ uri: 'http://lorempixel.com/output/cats-q-c-100-100-7.jpg' }} />
          </View>

          <View style={avatarContainer}>
            <Image style={avatar} source={{ uri: 'http://lorempixel.com/output/cats-q-c-100-100-3.jpg' }} />
          </View>

          <View style={avatarContainer}>
            <Image style={avatar} source={{ uri: 'http://lorempixel.com/output/cats-q-c-100-100-7.jpg' }} />
          </View>

        </View>
    );
  }
}


const styles = {
  overlapContainer: {
    flexDirection: 'row-reverse',
    justifyContent: 'flex-end',
    marginTop: 50,
    marginRight: 50
  },
  avatarContainer: {
    borderRadius: 33,
    height: 66,
    width: 66,
    marginLeft: -15,
    borderStyle: 'solid',
    borderWidth: 3,
    borderColor: 'white'
  },
  avatar: {
    borderRadius: 30,
    height: 60,
    width: 60
  }
}

React-native相关问答推荐

Redux toolkit通过按钮操作进行查询

如何在Reaction Native DrawerNavigation中添加注销功能

未执行迁移?

在 React Native 中打开后日期 Select 器不关闭

React Native:在ScrollView中更改焦点时键盘关闭

react-native-snap-carousel 无法正确渲染

React Native 转换与枢轴点

为应用创建单个 MobX store 的最佳方式是什么?

react-native-firebase crashlytics 未显示在 firebase 仪表板上

如何在 Crashlytics (Fabrics) 中有效地对非致命异常进行分组?

没有找到 `React-fishhook` 的 podspec

React Native ScrollView 在snapping后重新回到顶部

React Native 检测点击 View

axios 的网络错误和react-native

React Native 无法运行堆栈跟踪

如何从react-native应用程序打开外部应用程序?

React Native 中的 CSS 三角形

单击平面列表中的侦听器

React Native 项目,有时使用 expo start 获得连接 ECONNREFUSED 127.0.0.1:19001

Flatlist getItemLayout 用例