【问题标题】:How to display half of the image over another image in react native如何在本机反应中将图像的一半显示在另一个图像上
【发布时间】:2018-06-30 08:33:18
【问题描述】:

我正在用 react-native 制作一个应用程序,我必须在其中显示用户的个人资料图片。 I want to make UI of somewhat this type 。如附图所示,我们可以看到个人资料图片略微向上移动,具有图像背景。

我已经写了代码,但是整个个人资料图片都移到上面了

render() {

        return (
            <Container style={{ backgroundColor: '#FFFFFF', }}>




                <Content>



                    <Image source={{ uri: 'https://firebasestorage.googleapis.com/v0/b/reactnativechatapp-6f7eb.appspot.com/o/Ontro%20Copy%209.png?alt=media&token=2ede2451-0a14-4988-a9e2-ba88bab2c844' }}
                        style={styles.image}>



                        <View style={{
                            flexDirection: 'row', alignItems: 'flex-end', marginTop: 15,
                            justifyContent: 'flex-start', marginLeft: 20,
                            flex: 1
                        }}>
                            <Thumbnail source={{ uri: 'https://placeimg.com/640/480/people' }} />

                        </View>


                    </Image>






                    <View style={{
                        flexDirection: 'row', alignItems: 'flex-start',
                        justifyContent: 'flex-start', marginLeft: 40,
                        backgroundColor: '#FFFFFF', flex: 1
                    }}>


                        <View style={{ flexDirection: 'column', marginTop: 10, marginBottom: 15 }}>
                            <Text style={{ color: '#9F2232', marginLeft: 15, fontSize: 22, }}>Cecelia Fletcher</Text>


                            <Text style={{ color: '#9E9C9E', marginLeft: 15, fontSize: 12, }}>West Mambalam</Text>
                        </View>



                    </View>

                    <Separator />

如何为所附图片中的个人资料图片制作这种类型的 UI。

【问题讨论】:

  • 您是否尝试在顶部图像上使用负边距底部?还是底部图像上的负 marginTop?
  • 不,我没用过。你能通过更改我的代码来解释我吗
  • 我试过是说无效的道具
  • 负边距不起作用
  • 负边距裁剪android上的底部图像

标签: javascript reactjs react-native flexbox react-native-android


【解决方案1】:

如果您的个人资料图像将具有相同的高度和宽度,您可以为缩略图位置指定绝对位置,并为其指定一个顶部值和一个左侧值以得到相同的结果。

编辑

render() {

    return (
        <Container style={{ backgroundColor: '#FFFFFF', }}>




            <Content>



                <Image source={{ uri: 'https://firebasestorage.googleapis.com/v0/b/reactnativechatapp-6f7eb.appspot.com/o/Ontro%20Copy%209.png?alt=media&token=2ede2451-0a14-4988-a9e2-ba88bab2c844' }}
                    style={styles.image}/>


                 <View style={{
                        flexDirection: 'row', alignItems: 'flex-end', 
                        marginTop: 15,
                        justifyContent: 'flex-start', marginLeft: 20,
                        flex: 1,
                        position: 'absolute',
                        top: 30,
                        left: 16,
                    }}>
                        <Thumbnail source={{ uri: 'https://placeimg.com/640/480/people' }} />

                    </View>




                <View style={{
                    flexDirection: 'row', alignItems: 'flex-start',
                    justifyContent: 'flex-start', marginLeft: 40,
                    backgroundColor: '#FFFFFF', flex: 1
                }}>


                    <View style={{ flexDirection: 'column', marginTop: 10, marginBottom: 15 }}>
                        <Text style={{ color: '#9F2232', marginLeft: 15, fontSize: 22, }}>Cecelia Fletcher</Text>


                        <Text style={{ color: '#9E9C9E', marginLeft: 15, fontSize: 12, }}>West Mambalam</Text>
                    </View>



                </View>

                <Separator />

试试这个。我基本上从图像标签中删除了您的缩略图并给它一个绝对位置。您可以随意摆弄顶部和左侧的项目。

【讨论】:

  • 您能否更改我的代码并按我的方式显示然后图像根本没有显示请帮助我,我是 react-native 的新手
  • placeimg.com/640/480/people' }} />
  • 是的,很抱歉正在开车,但这应该将您的缩略图与您的图像重叠并像您想要的那样对齐它,给它一个顶部:(某个值)和左侧:(某个值)在 position:'absolute' 之后
  • 是的,它已经重叠,但它只停留在背景图像的末尾,当我给 paddingTop:30 但它没有下降时
  • placeimg.com/640/480/people' }} />
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2016-04-11
  • 2022-11-27
  • 2018-09-29
  • 2015-07-24
  • 2015-12-22
  • 1970-01-01
相关资源
最近更新 更多