ImageView的圆角 [英] ImageView rounded corners
本文介绍了ImageView的圆角的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想图像具有圆角。我实现这个XML code和使用这在我的图像视图。但图像重叠的形状。我通过异步任务下载图像。
< XML版本=1.0编码=UTF-8&GT?;
<形状的xmlns:机器人=http://schemas.android.com/apk/res/android
机器人:形状=矩形>
<边角机器人:半径=20dip/>
< /形状>
< ImageView的
机器人:ID =@ + ID / trVouchersImage
机器人:layout_width =55dp
机器人:layout_height =55dp
机器人:layout_marginLeft =8DP
机器人:layout_centerVertical =真
机器人:layout_centerHorizontal =真
机器人:layout_alignParentLeft =真
机器人:背景=@可绘制/ ash_arrow
/>
解决方案
我用通用图像装载库下载和圆形图像的角落,它为我工作。
ImageLoaderConfiguration配置=新ImageLoaderConfiguration.Builder(thisContext)
//你可以通过你自己的内存缓存实现
.discCacheFileNameGenerator(新的Hash codeFileNameGenerator())
。建立();
DisplayImageOptions选项=新DisplayImageOptions.Builder()
.displayer(新RoundedBitmapDisplayer(10))//圆角位图
.cacheInMemory(真)
.cacheOnDisc(真)
。建立();
ImageLoader的ImageLoader的= ImageLoader.getInstance();
imageLoader.init(配置);
imageLoader.displayImage(IMAGE_URL,image_view,期权);
I wanted image to have rounded corners. I implement this xml code and use this in my image view. but image overlap the shape. I am downloading the image through async task.
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="rectangle" >
<corners android:radius="20dip" />
</shape>
<ImageView
android:id="@+id/trVouchersImage"
android:layout_width="55dp"
android:layout_height="55dp"
android:layout_marginLeft="8dp"
android:layout_centerVertical="true"
android:layout_centerHorizontal="true"
android:layout_alignParentLeft="true"
android:background="@drawable/ash_arrow"
/>
解决方案
I use Universal Image loader library to download and round the corners of image, and it worked for me.
ImageLoaderConfiguration config = new ImageLoaderConfiguration.Builder(thisContext)
// You can pass your own memory cache implementation
.discCacheFileNameGenerator(new HashCodeFileNameGenerator())
.build();
DisplayImageOptions options = new DisplayImageOptions.Builder()
.displayer(new RoundedBitmapDisplayer(10)) //rounded corner bitmap
.cacheInMemory(true)
.cacheOnDisc(true)
.build();
ImageLoader imageLoader = ImageLoader.getInstance();
imageLoader.init(config);
imageLoader.displayImage(image_url,image_view, options );
这篇关于ImageView的圆角的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文