【问题标题】:How to make Images Circular in Android? [duplicate]如何在 Android 中制作圆形图像? [复制]
【发布时间】:2019-11-14 16:37:29
【问题描述】:
我正在尝试以最简单的方式制作圆形图像。但它只是行不通。
我也尝试过实现“hdodenhof/CircleImageView”,但没有用。
有没有其他可靠的方法可以做到这一点?
<com.google.android.material.card.MaterialCardView
android:layout_width="200dp"
android:layout_height="200dp"
app:cardCornerRadius="100dp">
<ImageView
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:src="@drawable/spongebob"/>
</com.google.android.material.card.MaterialCardView>
【问题讨论】:
标签:
android
xml
circleimage
【解决方案1】:
你见过ImageView in circular through xml 或
使用 Henning Dodenhof 创建的库 CircularImageView。你只需要在你的xml中写几行代码
<de.hdodenhof.circleimageview.CircleImageView
xmlns:app="http://schemas.android.com/apk/res-auto"
android:id="@+id/profile_image"
android:layout_width="96dp"
android:layout_height="96dp"
android:src="@drawable/profile"
app:civ_border_width="2dp"
app:civ_border_color="#FF000000"/>
【解决方案2】:
尝试使用CircularImageView库:
<com.mikhaellopez.circularimageview.CircularImageView
android:layout_width="250dp"
android:layout_height="250dp"
android:src="@drawable/spongebob"
app:civ_border_color="#ffffff"
app:civ_border_width="2dp"
app:civ_shadow="true"
app:civ_shadow_radius="5"
app:civ_shadow_color="#ff9999"/>
在 build.gradle 中:
implementation 'com.mikhaellopez:circularimageview:3.2.0'