您的位置:首页 > 其它

RadialGradient环形渲染

2015-09-13 21:58 323 查看


public RadialGradient(float x, float y, float radius, int[] colors, float[] positions,Shader.TileMode tile)


float x: 圆心X坐标


float y: 圆心Y坐标


float radius: 半径

int[] colors: 渲染颜色数组

floate[] positions: 相对位置数组,可为null, 若为null,可为null,颜色沿渐变线均匀分布



Shader.TileMode tile:[b]渲染器平铺模式[/b]


public RadialGradient(float x, float y, float radius, int color0, int color1,Shader.TileMode tile)


float x: 圆心X坐标


float y: 圆心Y坐标


float radius: 半径

int color0: 圆心颜色

int color1: 圆边缘颜色

Shader.TileMode tile:[b]渲染器平铺模式[/b]



[b]主要代码:[/b]


public class RadialGradientActivity extends Activity {
    ImageView image,image2,image3,image4;
    int width,height;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);
        image = (ImageView) findViewById(R.id.image);
        image2 = (ImageView) findViewById(R.id.image2);
        image3 = (ImageView) findViewById(R.id.image3);
        image4 = (ImageView) findViewById(R.id.image4);
        width = ValueUtil.dp2px(this, 120);
        height = ValueUtil.dp2px(this, 120);

        Bitmap bitmapTemp = Bitmap.createBitmap(width, height, Bitmap.Config.ARGB_8888);
        Canvas canvas = new Canvas(bitmapTemp);
        RadialGradient mShader = new RadialGradient(width/2, height/2,height/2, new int[]{
                Color.RED, Color.GREEN, Color.BLUE},
                null, Shader.TileMode.MIRROR);
        Paint paint = new Paint();
        paint.setShader(mShader);
        canvas.drawCircle(width/2, height/2,height/2,paint);
        image.setImageBitmap(bitmapTemp);

        Bitmap bitmapTemp2 = Bitmap.createBitmap(width, height, Bitmap.Config.ARGB_8888);
        Canvas canvas2 = new Canvas(bitmapTemp2);
        RadialGradient mShader2 = new RadialGradient(width/2, height/2,height/2, new int[]{
                Color.RED, Color.GREEN, Color.BLUE},
                null, Shader.TileMode.MIRROR);
        Paint paint2 = new Paint();
        paint2.setShader(mShader2);
        canvas2.drawCircle(width / 2, height / 2 + 50, height / 2, paint2);
        image2.setImageBitmap(bitmapTemp2);

        Bitmap bitmapTemp3 = Bitmap.createBitmap(width, height, Bitmap.Config.ARGB_8888);
        Canvas canvas3 = new Canvas(bitmapTemp3);
        RadialGradient mShader3 = new RadialGradient(width/2, height/2, 48,
                new int[] { 0x88ffffff, Color.TRANSPARENT },new float[]{0.01f,0.99f}, Shader.TileMode.REPEAT);
        Paint paint3 = new Paint();
        paint3.setShader(mShader3);
        canvas3.drawRect(new RectF(0, 0, width, height), paint3);
        image3.setImageBitmap(bitmapTemp3);
        image3.setBackgroundResource(R.drawable.tupian);

    }
}


效果图:

[b]


[/b]





[b]参考资料:/article/1875779.html[/b]

[b]/article/1875778.html

[/b]


[b]源码:http://yunpan.cn/c3f2qgcVtNSwP (提取码:2ccf)[/b]

内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: