android 圆角边框及图片

原文地址为: android 圆角边框及图片

my_wane_shape.xml 

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

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

<?xml version="1.0" encoding="utf-8"?> 

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

<item android:drawable="@drawable/background_img"/> 

<item android:drawable="@drawable/wane_shape"/>

</layer-list> 

  

wane_shape.xml:

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

<?xml version="1.0" encoding="utf-8"?> 

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

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

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

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

{

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

    <corners android:topLeftRadius="10dp"   

     android:topRightRadius="10dp"

     android:bottomRightRadius="10dp"      

     android:bottomLeftRadius="10dp"/>  

}

</shape> 

或者直接使用一种效果

<?xml version="1.0" encoding="UTF-8"?> 

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

<solid android:color="#99FFFFFF"/> 

<corners android:radius="30px"/> 

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

</shape>

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

 android:background="@drawable/my_wane_shape" 

2.图片本身加上圆角

public static Bitmap toRoundCorner(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; }

  


转载请注明本文地址: android 圆角边框及图片

猜你喜欢

转载自blog.csdn.net/w36680130/article/details/81409993