android中能够绘制圆角矩形。html
1.利用画布cavas绘制java
若是提供了一个方法能够在画布上绘制圆角矩形:android
函数名称:public void drawRoundRect (RectF rect, float rx, float ry, Paint paint)canvas
参数说明:函数
rect:RectF对象。
rx:x方向上的圆角半径。
ry:y方向上的圆角半径。
paint:绘制时所使用的画笔。
spa
示列: debug
Paint _debugInfoPaint = new Paint(Paint.ANTI_ALIAS_FLAG); //设置无锯齿 也可使用setAntiAlias(true) _debugInfoPaint.setColor(Color.GREEN);//设置画笔颜色 _debugInfoPaint.setAlpha(200); _debugInfoPaint.setStrokeWidth(1.5f);//设置线宽 _debugInfoPaint.setStyle(Paint.Style.STROKE);//设置样式:FILL表示颜色填充整个;STROKE表示空心 canvas.drawRoundRect(new RectF(0, 0, 300, 300), 10, 10, _debugInfoPaint);2.xml中设置
创建 rect_gray.xml文件放在drawable文件夹下面 code
<?xml version="1.0" encoding="utf-8"?> <shape xmlns:android="http://schemas.android.com/apk/res/android" android:shape="rectangle"> <!-- 填充颜色 --> <solid android:color="#FFFFFF"></solid> <!-- 线的宽度,颜色灰色 --> <stroke android:width="1dp" android:color="#D5D5D5"></stroke> <!-- 矩形的圆角半径 --> <corners android:radius="0dp" /> </shape>而后在使用的地方引用:
<LinearLayout android:id="@+id/activity_myhezu_wantchuzu" android:layout_width="wrap_content" android:layout_height="wrap_content" android:background="@drawable/myhezu_dottedline_rect_green" android:orientation="horizontal" >