【发布时间】:2015-10-18 22:57:30
【问题描述】:
我在网站上搜索了更多,并得到了很多如下建议
使用自定义样式更改背景以设置角半径和填充(将图像获取为矩形,将背景获取为圆角)
通过解码图像将给定图像更改为位图,并通过传递此位图和宽度来裁剪功能(加载需要更多时间)
我已经检查了WhatsApp Chat history list and it has rounded corner images but its loaded with minimum time。
您能否建议我使用 WhatsApp 中的圆形图像创建列表视图模板的最佳方法?
我希望通过在 xml 页面中设置样式详细信息来更改带有圆角的图像。 (图像宽度和高度为 60 dp,我的列表视图也有大约 60 个项目)
参考资料:
- https://xjaphx.wordpress.com/2011/06/23/image-processing-image-with-round-corner/
- How to Make an ImageView in Circular Shape?
- How to create a circular ImageView in Android?
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
【问题讨论】:
-
你是如何设置 ImageView 的?从资源还是从其他地方下载位图?
-
stackover flow 已经有了答案,请参考这个stackoverflow.com/questions/2459916/…
-
@bGorle: 是的,我试过了,加载图片需要更多时间
-
使用
android.support.v4.graphics.drawable.RoundedBitmapDrawable -
检查这个现在我们有
ShapeableImageView来制作圆形或圆形的imageView stackoverflow.com/a/61086632/7666442
标签: android android-listview android-imageview android-xml