Android圆角图片

my_wane_shape.xml

快速圆角背景边框实现,不太好用:

注:是图层的累加,字面上是多个层,也就是你可以把多个leyaer放在一起然后一其显现出来,类似于framelayout。

<spanclass="Apple-style-span"><?xmlversion="1.0"encoding="utf-8"?>

<layer-listxmlns:android="http://schemas.android.com/apk/res/android">

<itemandroid:drawable="@drawable/</span><spanclass="Apple-style-span"style="font-family:verdana,Arial,Helvetica,sans-serif;line-height:30px;white-space:normal;background-color:#ffffff;">background</span><spanclass="Apple-style-span">_img"/>

<itemandroid:drawable="@drawable/wane_shape"/>

</layer-list>

</span>

wane_shape.xml:

自定义方形圆角背景如下:

<?xmlversion="1.0"encoding="utf-8"?>

<shapexmlns:android="http://schemas.android.com/apk/res/android">

<solidandroid:color="自定义背景颜色"/>

<strokeandroid:width="3dp"color="#ff000000"/>

<cornersandroid:radius="自定义角度dp"/>

{

//或者分步定义没个圆角。

<cornersandroid:topLeftRadius="10dp"

android:topRightRadius="10dp"

android:bottomRightRadius="10dp"

android:bottomLeftRadius="10dp"/>

}

</shape>

或者直接使用一种效果

<?xmlversion="1.0"encoding="UTF-8"?>

<shapexmlns:android="http://schemas.android.com/apk/res/android">

<solidandroid:color="#99FFFFFF"/>

<cornersandroid:radius="30px"/>

<paddingandroid:left="0dp"android:top="0dp"android:right="0dp"android:bottom="0dp"/>

</shape>

调用语句:通常在你所希望的layout背景中应用

android:background="@drawable/my_wane_shape"

2.图片本身加上圆角

publicstaticBitmaptoRoundCorner(Bitmapbitmap,intpixels){

Bitmapoutput=Bitmap.createBitmap(bitmap.getWidth(),bitmap.getHeight(),Config.ARGB_8888);

Canvascanvas=newCanvas(output);

finalintcolor=0xff424242;

finalPaintpaint=newPaint();

finalRectrect=newRect(0,0,bitmap.getWidth(),bitmap.getHeight());

finalRectFrectF=newRectF(rect);

finalfloatroundPx=pixels;

paint.setAntiAlias(true);

canvas.drawARGB(0,0,0,0);

paint.setColor(color);

canvas.drawRoundRect(rectF,roundPx,roundPx,paint);

paint.setXfermode(newPorterDuffXfermode(Mode.SRC_IN));

canvas.drawBitmap(bitmap,rect,rect,paint);<br>

returnoutput;

}