ImageView rounded corners

后端 未结 17 1998
长发绾君心
长发绾君心 2020-11-27 15:33

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.<

17条回答
  •  执念已碎
    2020-11-27 16:13

    Your MainActivity.java is like this:

    LinearLayout ll = (LinearLayout) findViewById(R.id.ll);
    ImageView iv = (ImageView) findViewById(R.id.iv);
    

    You should to first get your image from Resource as Bitmap or Drawable.

    If get as Bitmap:

    Bitmap bm = BitmapFactory.decodeResource(getResources(), R.drawable.ash_arrow);
    bm = new Newreza().setEffect(bm, 0.2f, ((ColorDrawable) ll.getBackground).getColor);
    iv.setImageBitmap(bm);
    

    Or if get as Drawable:

    Drawable d = getResources().getDrawable(R.drawable.ash_arrow);
    d = new Newreza().setEffect(d, 0.2f, ((ColorDrawable) ll.getBackground).getColor);
    iv.setImageDrawable(d);
    

    Then create new file as Newreza.java near MainActivity.java, and copy bottom codes in Newreza.java:

    package your.package.name;
    import android.content.res.Resources;
    import android.graphics.Bitmap;
    import android.graphics.drawable.BitmapDrawable;
    import android.graphics.drawable.Drawable;
    //Telegram:@newreza
    //mail:newreza7@gmail.com
    public class Newreza{
        int a,x,y;
        float bmr;
        public Bitmap setEffect(Bitmap bm,float radius,int color){
            bm=bm.copy(Bitmap.Config.ARGB_8888,true);
            bmr=radius*bm.getWidth();
            for(y=0;y

    Just notice that replace your package name with first line in the code.

    It %100 works, because is written in details :)

提交回复
热议问题