Android的自定形状 [英] Android custom shape

查看:165
本文介绍了Android的自定形状的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我知道它有可能使一个形状看起来像这样:

I know it is possible to make a shape looking something like this:

但我不知道如何开始使用它。我可以把它作为一个形状?或做我必须做点别的?

But I don't know how to start with it. Can I make it as a shape? or do I have to do something else?

BR

推荐答案

哦,看看那个,我错了 - 梯度都不是问题:

Oh look at that, I was wrong - gradients are not a problem:

import android.content.Context;
import android.graphics.Canvas;
import android.graphics.Color;
import android.graphics.LinearGradient;
import android.graphics.Paint;
import android.graphics.Rect;
import android.graphics.RectF;
import android.graphics.Shader;
import android.view.View;

public class ButtonShadow extends View {

    public ButtonShadow(Context context)
    {
        super(context);
    }

    @Override
    public void onDraw(Canvas canvas)
    {
        RectF space = new RectF(this.getLeft(), this.getTop(), this.getRight(), this.getBottom());

        Paint paint = new Paint(Paint.ANTI_ALIAS_FLAG);

        paint.setShader(new LinearGradient(0, getWidth(), 0, 0, Color.BLACK, Color.WHITE, Shader.TileMode.MIRROR));

        canvas.drawArc(space, 180, 360, true, paint);

        Rect rect = new Rect(this.getLeft(),this.getTop() + (this.getHeight() / 2),this.getRight(),this.getBottom());
        canvas.drawRect(rect, paint);
    }
}

更多关于渐变填充看这里:<一href="http://stackoverflow.com/questions/2836098/how-to-fill-a-path-in-android-with-a-linear-gradient">How填写Android的一个路径的线性梯度?

这篇关于Android的自定形状的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆