gpt4 book ai didi

android - 在 ImageView 中设置圆角图像

转载 作者:塔克拉玛干 更新时间:2023-11-02 20:26:06 28 4
gpt4 key购买 nike

我在网站上搜索了更多,得到了很多如下建议

  • 使用自定义样式更改背景以设置角半径和填充(获取图像为矩形和背景为圆角)

  • 通过解码图像将给定图像更改为位图,并通过传递此位图和宽度来裁剪功能(加载需要更多时间)

我检查了 WhatsApp 聊天历史列表,它有圆角图像,但加载时间最短

能否请您建议我使用 WhatsApp 中的圆形图像创建 ListView 模板的最佳方法?

我希望通过在 xml 中设置样式详细信息来更改带有圆角的图像 页面。 (图像宽度和高度为 60 dp,我的 ListView 也有大约 60 个项目)

引用文献:

res/mylayout.xml:

<ImageView
android:id="@+id/contactssnap"
android:layout_width="50dp"
android:layout_height="50dp"
android:src="@drawable/contactssnap"
android:background="@drawable/roundimage" />

res/drawable/roundimage.xml:

<?xml version="1.0" encoding="UTF-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="rectangle" >
<solid android:color="#ffffffff" />
<stroke
android:width="2dp"
android:color="#90a4ae" />
<size
android:height="50dp"
android:width="50dp" />
<padding
android:bottom="2dp"
android:left="2dp"
android:right="2dp"
android:top="2dp" />
<corners android:radius="100dp" />
</shape>

注意:支持Android版本14-22

最佳答案

Material 组件库提供了新的ShapeableImageView
只需使用如下布局:

  <com.google.android.material.imageview.ShapeableImageView
...
app:shapeAppearanceOverlay="@style/roundedCorners"
app:srcCompat="@drawable/...." />

使用 shapeAppearanceOverlay 属性,您可以应用自定义形状,在本例中为圆角:

  <style name="roundedCorners" parent="">
<item name="cornerFamily">rounded</item>
<item name="cornerSize">xxdp</item>
</style>

enter image description here

*注意:它至少需要 1.2.0-alpha03 版本。

关于android - 在 ImageView 中设置圆角图像,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31675420/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com