具有自定义形状的自定义ImageView

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

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

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

Photo examples

android view imageview
2个回答
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"/>


0
投票

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

© www.soinside.com 2019 - 2024. All rights reserved.