您可以使用通用圖像裝載機。
https://github.com/nostra13/Android-Universal-Image-Loader。
可用於顯示帶圓角的位圖。檢查上面的鏈接。
在您的自定義適配器構造
File cacheDir = StorageUtils.getOwnCacheDirectory(a, "your folder");
// Get singletone instance of ImageLoader
imageLoader = ImageLoader.getInstance();
// Create configuration for ImageLoader (all options are optional)
ImageLoaderConfiguration config = new ImageLoaderConfiguration.Builder(a)
// You can pass your own memory cache implementation
.discCache(new UnlimitedDiscCache(cacheDir)) // You can pass your own disc cache implementation
.discCacheFileNameGenerator(new HashCodeFileNameGenerator())
.enableLogging()
.build();
// Initialize ImageLoader with created configuration. Do it once.
imageLoader.init(config);
options = new DisplayImageOptions.Builder()
.showStubImage(R.drawable.stub_id)//display stub image
.cacheInMemory()
.cacheOnDisc()
.displayer(new RoundedBitmapDisplayer(20)) //rounded corner bitmap
.build();
在你getView()
ImageView image=(ImageView)vi.findViewById(R.id.imageview);
imageLoader.displayImage(imageurl, image,options);//provide imageurl, imageview and options
你可以用其他選項配置,以滿足您的需求。帶圓角
羅曼球員圖像@http://www.curious-creature.org/2012/12/11/android-recipe-1-image-with-rounded-corners/
實測值以下@How to make an ImageView with rounded corners?
http://ruibm.com/?p=184。
public class ImageHelper {
public static Bitmap getRoundedCornerBitmap(Bitmap bitmap, int pixels) {
Bitmap output = Bitmap.createBitmap(bitmap.getWidth(), bitmap
.getHeight(), Config.ARGB_8888);
Canvas canvas = new Canvas(output);
final int color = 0xff424242;
final Paint paint = new Paint();
final Rect rect = new Rect(0, 0, bitmap.getWidth(), bitmap.getHeight());
final RectF rectF = new RectF(rect);
final float roundPx = pixels;
paint.setAntiAlias(true);
canvas.drawARGB(0, 0, 0, 0);
paint.setColor(color);
canvas.drawRoundRect(rectF, roundPx, roundPx, paint);
paint.setXfermode(new PorterDuffXfermode(Mode.SRC_IN));
canvas.drawBitmap(bitmap, rect, rect, paint);
return output;
}
}
getRoundedCornerBitmap()方法是我一直在尋找 – 2013-09-24 07:53:43
嗨,你能告訴我怎麼做圖像的右側頂部和右側BUTTOM圓而左側? – 2013-10-04 06:43:17
@SampathKumar,你應該問一個新問題。此外,請檢查是否可以幫助您:http://stackoverflow.com/questions/15962745/draw-a-semicircle-in-the-background-of-a-view,或 http://developer.android.com/參考/機器人/圖形/ Canvas.html – dwbrito 2014-10-20 13:07:20