ICode9

精准搜索请尝试: 精确搜索
首页 > 其他分享> 文章详细

android – 在ImageView中设置圆角图像

2019-07-16 07:23:10  阅读:207  来源: 互联网

标签:android android-listview android-imageview android-xml


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

>使用自定义样式更改背景以设置角半径和填充(将图像设置为矩形,将背景设置为圆角)
>通过传递此位图和宽度(它需要更多时间加载)来解码图像和裁剪功能,从而将给定图像更改为位图

我已经检查了WhatsApp聊天记录列表,它有圆角图像,但加载的时间最短.

你能否建议我用WhatsApp创建带有圆形图像的listview模板的最佳方法?

我希望通过在xml页面中设置样式详细信息来更改带圆角的图像. (图像宽度和高度是60 dp,我的listview也有大约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 /绘制/ 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

解决方法:

sats的答案是有效的.但是RoundedBitmapDrawable无法应用于scaleType:centerCrop的ImageView.

更新.

如果您在21级使用Android API.我们在这里有一个简单的解决方案.

1,创建drawable作为imageview的背景

<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="rectangle">
<corners android:radius="8dp" />
<solid android:color="@android:color/white" />

<stroke
    android:width="1dp"
    android:color="@color/colorWhite" />
</shape>

接下来,将ImageView的属性setClipToOutline更改为true.并将roundled drawable设置为ImageView的背景.

而已.

enter image description here

在我的演示中,我使用此方法进行圆形imageview.可以在这里找到它cuberto’s dialog

标签:android,android-listview,android-imageview,android-xml
来源: https://codeday.me/bug/20190716/1476070.html

本站声明: 1. iCode9 技术分享网(下文简称本站)提供的所有内容,仅供技术学习、探讨和分享;
2. 关于本站的所有留言、评论、转载及引用,纯属内容发起人的个人观点,与本站观点和立场无关;
3. 关于本站的所有言论和文字,纯属内容发起人的个人观点,与本站观点和立场无关;
4. 本站文章均是网友提供,不完全保证技术分享内容的完整性、准确性、时效性、风险性和版权归属;如您发现该文章侵犯了您的权益,可联系我们第一时间进行删除;
5. 本站为非盈利性的个人网站,所有内容不会用来进行牟利,也不会利用任何形式的广告来间接获益,纯粹是为了广大技术爱好者提供技术内容和技术思想的分享性交流网站。

专注分享技术,共同学习,共同进步。侵权联系[81616952@qq.com]

Copyright (C)ICode9.com, All Rights Reserved.

ICode9版权所有