我怎么能为ImageView / FrameLayout做一个特殊的圆角形状?

问题描述 投票:0回答:1

正如你可以看到here我尝试为我的FrameLayout制作圆角。这是我的rounded_shape.xml形状:

<?xml version="1.0" encoding="UTF-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
       android:shape="rectangle">
    <solid android:color="@android:color/transparent"/>
    <stroke android:width="@dimen/margin"
            android:color="@color/colorBackground"/>
    <corners android:radius="24dp" />
</shape>

这看起来如此:rounded_shape.xml Preview

当我在我的代码中执行:frameLayout.setBackground(new BitmapDrawable(getResources(),bitmapPhoto.bitmap)); frameLayout.setForeground(getResources()getDrawable(R.drawable.rounded_shape));它看起来像这样:result on app

您可以通过圆角看到黑色边缘。

我怎么能做这样的形状:where the the edges are rounded and the black parts are gone already

android imageview android-imageview rounded-corners android-framelayout
1个回答
0
投票

我做了两个平行的形状。

  • 一个圆角的形状,内圆角。
  • 一个有尖角的形状,外角锐利

所有结构都在layer-list中,如下所示:

<?xml version="1.0" encoding="UTF-8"?>
<layer-list>
    <item>
        <shape xmlns:android="http://schemas.android.com/apk/res/android"
            android:shape="rectangle">
            <solid android:color="@android:color/transparent" />
            <stroke
                android:width="@dimen/margin"
                android:color="@color/color" />
            <corners android:radius="24dp" />
        </shape>
    </item>
    <item>
        <shape xmlns:android="http://schemas.android.com/apk/res/android"
            android:shape="rectangle">
            <solid android:color="@android:color/transparent" />
            <stroke
                android:width="@dimen/margin"
                android:color="@color/color" />
        </shape>
    </item>
</layer-list>
© www.soinside.com 2019 - 2024. All rights reserved.