java - Can't put circular imageview in adapter -
java - Can't put circular imageview in adapter -
i have listview custom adapter in there imageview. imageview circular , to utilize class:
public class circularimageview extends imageview { public circularimageview(context context) { super(context); // todo auto-generated constructor stub } public circularimageview(context context, attributeset attrs) { super(context, attrs); } public circularimageview(context context, attributeset attrs, int defstyle) { super(context, attrs, defstyle); } @override protected void ondraw(canvas canvas) { drawable drawable = getdrawable(); if (drawable == null) { return; } if (getwidth() == 0 || getheight() == 0) { return; } bitmap b = ((bitmapdrawable)drawable).getbitmap() ; bitmap bitmap = b.copy(bitmap.config.argb_8888, true); int w = getwidth(), h = getheight(); bitmap roundbitmap = getcroppedbitmap(bitmap, w); canvas.drawbitmap(roundbitmap, 0,0, null); } public static bitmap getcroppedbitmap(bitmap bmp, int radius) { bitmap sbmp; if(bmp.getwidth() != radius || bmp.getheight() != radius) sbmp = bitmap.createscaledbitmap(bmp, radius, radius, false); else sbmp = bmp; bitmap output = bitmap.createbitmap(sbmp.getwidth(), sbmp.getheight(), config.argb_8888); canvas canvas = new canvas(output); final int color = 0xffa19774; final paint paint = new paint(); final rect rect = new rect(0, 0, sbmp.getwidth(), sbmp.getheight()); paint.setantialias(true); paint.setfilterbitmap(true); paint.setdither(true); canvas.drawargb(0, 0, 0, 0); paint.setcolor(color.parsecolor("#bab399")); canvas.drawcircle(sbmp.getwidth() / 2+0.7f, sbmp.getheight() / 2+0.7f, sbmp.getwidth() / 2+0.1f, paint); paint.setxfermode(new porterduffxfermode(mode.src_in)); canvas.drawbitmap(sbmp, rect, rect, paint); homecoming output; } }
if write in layout xml
<com.myapp.utility.circularimageview android:id="@+id/image" android:layout_centervertical="true" android:layout_width="75dp" android:layout_height="75dp" android:layout_marginleft="16dp" android:adjustviewbounds="true" android:src="@drawable/icon" android:scaletype="centercrop" />
it works! , image rounded. imageview more 1 , add together @ adapter in way:
@override public view getview(int i, view view, viewgroup viewgroup) { if (view == null) { view = layoutinflater.from(viewgroup.getcontext()).inflate(r.layout.grid_item, viewgroup, false); } imageview image = (imageview) view.findviewbyid(r.id.image); image.setbackgroundresource(myimagelist[i]); textview text = (textview) view.findviewbyid(r.id.text); text.settext(names[i]); textview textspec = (textview) view.findviewbyid(r.id.text_spec); textspec.settext(ruolo[i]); homecoming view; }
in here: image.setbackgroundresource(myimagelist[i]);
set images can't show images circular when set image static. tried write:
circularimageview image = (circularimageview) view.findviewbyid(r.id.image);
but still not change..what's wrong?
java android android-listview custom-adapter
Comments
Post a Comment