【问题标题】:How could I do a special round corner shape for ImageView/FrameLayout?如何为 ImageView/FrameLayout 做一个特殊的圆角形状?
【发布时间】:2018-11-19 10:58:43
【问题描述】:

如您所见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】:

    我做了两个平行的形状。

    • 圆角形状,内角圆。
    • 带尖角的形状,外角锐利

    所有结构都在 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>
    

    【讨论】:

      猜你喜欢
      • 2016-04-14
      • 1970-01-01
      • 2020-11-29
      • 2020-04-23
      • 2016-07-12
      • 2015-12-24
      • 2020-04-02
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多