android绘制圆角矩形

       android中可以绘制圆角矩形。

       1.利用画布cavas绘制

       如果提供了一个方法可以在画布上绘制圆角矩形:

      函数名称:public void drawRoundRect (RectF rect, float rx, float ry, Paint paint)

      参数说明:

                 rect:RectF对象。
                rx:x方向上的圆角半径。
                ry:y方向上的圆角半径。
               paint:绘制时所使用的画笔。

    示列:    

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文件夹下面     

 <?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" >


  • 4
    点赞
  • 10
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值