圆角矩形“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 on
the inner rectangle, pass null. If inset parameter is null, this parameter is ignored. 

//同第一个参数。

例子如下:

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);

	}
}

 

效果图:


本文转自农夫山泉别墅博客园博客,原文链接:http://www.cnblogs.com/yaowen/p/5438984.html,如需转载请自行联系原作者

相关文章
|
1天前
|
Python
绘制矩形
【5月更文挑战第9天】绘制矩形。
6 2
|
9月前
|
机器学习/深度学习 存储 人工智能
391. 完美矩形
391. 完美矩形
41 0
|
10月前
|
移动开发 HTML5
使用三次贝塞尔曲线绘制弧形菜单
使用三次贝塞尔曲线绘制弧形菜单
Core Animation - 如何来绘制三个圆角一个直角的矩形
Core Animation - 如何来绘制三个圆角一个直角的矩形
54 0
|
C# 图形学
C#之深入理解GDI+绘制圆弧及圆角矩形等比缩放的绘制
GDI+中对于圆弧的绘制,是以给定的长方形(Rectangle`结构)为边界绘制的椭圆的一部分形成的圆弧。绘制的圆弧的中心为长方形内切椭圆的圆心(如果是正方形,则正方形的...
435 0
C#之深入理解GDI+绘制圆弧及圆角矩形等比缩放的绘制
C#编程-132:DrawRectangle绘制矩形
C#编程-132:DrawRectangle绘制矩形
139 0
C#编程-132:DrawRectangle绘制矩形
|
C++
201312-3 最大的矩形
201312-3 最大的矩形
42 0
201312-3 最大的矩形
shape颜色渐变、圆角、半圆角、边框、填充
shape颜色渐变、圆角、半圆角、边框、填充
397 0
shape颜色渐变、圆角、半圆角、边框、填充
|
前端开发 API
Canvas绘制圆点线段
Canvas绘制圆点线段
Canvas绘制圆点线段