【问题标题】:Border radius on image not working (Android)图像上的边框半径不起作用(Android)
【发布时间】:2020-10-04 00:23:22
【问题描述】:

我正在尝试获取带有圆角的图像,以便可以说它变成圆形图像。我正在使用 vue-nativescript。

html:

<template>
    <Page>
        <FlexboxLayout flexDirection="column" justifyContent="space-around">
        <StackLayout class="stack-layout-logo">
            <Image
                src="~/assets/images/passer.png"
                stretch="aspectFit"
                class="image-logo"
            ></Image>
        </StackLayout>
        <StackLayout class="stack-layout-logo">
            <Image
                src="~/assets/images/passer.png"
                stretch="aspectFill"
                class="image-logo"
            ></Image>
        </StackLayout>
        <StackLayout class="stack-layout-logo">
            <Image src="~/assets/images/passer.png" stretch="none" class="image-logo"></Image>
        </StackLayout>
        </FlexboxLayout>
    </Page>
</template>

css:

.stack-layout-logo {
    background-color: lime;
    height: 25%;
}

.image-logo {
    background-color: grey;
    border-radius: 50% 50% 50% 50%;
    height: 100%;
}

我尝试了不同的伸展运动,但似乎没有一个能达到我想要的效果。

【问题讨论】:

    标签: css nativescript


    【解决方案1】:

    简单的bordrRadius 不适用于Android,您必须提供所有4 个角的边框半径,即topRight、topLeft、bottomRight 和bottomLeft

    const width = 20 // whatever is width of your image
    const imgStyle = {
      borderRadius: width / 2,
      borderBottomLeftRadius: width / 2,
      borderBottomRightRadius: width / 2,
      borderTopRightRadius: width / 2,
      borderTopLeftRadius: width / 2
    }
    

    【讨论】:

      【解决方案2】:

      尝试将stretch = "aspectFit" 替换为stretch = "aspectFill"stretch = "none"。我以前也经历过同样的事情

      【讨论】:

        【解决方案3】:

        根据doc,你应该这样使用:

        .image-logo {
            background-color: grey;
            border-radius: 20;
            height: 100%;
        }
        

        如果你想圆一个特定的角落,你可以试试这个:

        https://reactnative.dev/docs/view-style-props#borderbottomleftradius

        不错的图片顺便说一句。

        【讨论】:

        • 您好!我想知道 ReactNative 和 NativeScript 是否如此相似?我确实尝试了您的更改但无济于事:(
        • 大声笑,我的 SO 将您的问题标记为 react-native 问题。对不起,伙计。我应该删除它吗?
        • 不,离开吧!它可能只是帮助一个反应老兄!我确实想出了如何解决这个问题,很快就会自己发布答案:P
        猜你喜欢
        • 2013-05-13
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2013-02-12
        • 2011-10-27
        • 2022-08-23
        • 1970-01-01
        • 2022-01-28
        相关资源
        最近更新 更多