【问题标题】:Custom ImageView With a Custom Shape具有自定义形状的自定义 ImageView
【发布时间】:2016-12-27 10:23:40
【问题描述】:

我正在尝试创建一个自定义 ImageView,它在自定义边框和形状而不是默认矩形内显示图像,并且边框的外侧是 TransParent。

我的边框是一个 SVG 文件,我该怎么做?谢谢

【问题讨论】:

标签: android view imageview


【解决方案1】:

使用这个库siyamed/android-shape-imageview 或创建一个自定义视图,从 View 类扩展并覆盖方法!

但最简单的方法是使用这个库

创建一个您想要遮盖原始图片的位图并使用它,如下所示:

 <com.github.siyamed.shapeimageview.mask.PorterShapeImageView
                android:layout_width="match_parent"
                android:layout_height="match_parent"
                android:layout_weight="1"
                android:layout_margin="8dp"
                app:siShape="@drawable/octogon" <!--mask bitmap-->
                android:src="@drawable/neo" <!-- original bitmap -->
app:siSquare="true"/>

【讨论】:

    【解决方案2】:

    扩展 Image View 类并根据您的使用进行更改。不只是图像视图,您可以自定义任何只需要扩展父类的视图类。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2016-11-01
      • 2023-03-06
      • 2012-11-06
      • 1970-01-01
      • 1970-01-01
      • 2022-01-11
      • 2014-06-21
      相关资源
      最近更新 更多