圆角矩形“RoundRectShape”使用详解

圆角矩形 常用作一些组件的背景

构造函数:

RoundRectShape(float[] outerRadii, RectF inset, float[] innerRadii)

Specifies an outer (round)rect and an optional inner (round)rect.// 指定一个外部(圆角)矩形 和 一个 可选的 内部(圆角)矩形。

Parameters:

outerRadii

An array of 8 radius values, for the outer roundrect. The first two floats are for the top-left corner (remaining pairs correspond clockwise). For no rounded corners on the outer rectangle, pass null.

//一个包含8个弧度值,指定外部圆角矩形的 4个角部的弧度及 :new float[] {l, l, t, t, r, r, b, b};

// 前2个 左上角, 3 4 , 右上角, 56, 右下, 78 ,左下,如果没弧度的话,传入null即可。

inset

A RectF that specifies the distance from the inner rect to each side of the outer rect. For no inner, pass null.

//指定外部矩形4条边 与内部矩形的4条边的个距离,也用RectF的方式指定。

innerRadii

An array of 8 radius values, for the inner roundrect. The first two floats are for the top-left corner (remaining pairs correspond clockwise). For no rounded corners onthe inner rectangle, pass null. If inset parameter is null, this parameter is ignored.

//同第一个参数。

例子如下:

[java] view plain copy 在CODE上查看代码片派生到我的代码片
package com.example.testroundrectshape;

import android.app.Activity;
import android.graphics.Color;
import android.graphics.Paint;
import android.graphics.RectF;
import android.graphics.drawable.ShapeDrawable;
import android.graphics.drawable.shapes.RoundRectShape;
import android.os.Bundle;
import android.view.Menu;
import android.widget.TextView;

public class MainActivity extends Activity {

@Override  
protected void onCreate(Bundle savedInstanceState) {  
    super.onCreate(savedInstanceState);  
    setContentView(R.layout.activity_main);  
    TextView test = (TextView) findViewById(R.id.test);  
    // 外部矩形弧度  
    float[] outerR = new float[] { 8, 8, 8, 8, 8, 8, 8, 8 };  
    // 内部矩形与外部矩形的距离  
    RectF inset = new RectF(100, 100, 50, 50);  
    // 内部矩形弧度  
    float[] innerRadii = new float[] { 20, 20, 20, 20, 20, 20, 20, 20 };  

    RoundRectShape rr = new RoundRectShape(outerR, inset, null);  
    ShapeDrawable drawable = new ShapeDrawable(rr);  
    //指定填充颜色  
    drawable.getPaint().setColor(Color.YELLOW);  
    // 指定填充模式  
    drawable.getPaint().setStyle(Paint.Style.FILL);  

    test.setBackgroundDrawable(drawable);  

}  

}

效果图:
这里写图片描述

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值