ShowCaseView圆圈大小

Jay*_*ayR 1 android showcaseview

是否可以在ShowCaseView中更改圆的当前大小?

我的代码中包含以下内容:

ShowcaseView.ConfigOptions co = new ShowcaseView.ConfigOptions();
            co.hideOnClickOutside = false;
            return ShowcaseView.insertShowcaseView(id, activity, title, message, co);
Run Code Online (Sandbox Code Playgroud)

但是现在,我只是显示ShowCaseView的默认大小,如果是这样我怎么调整大小?

谢谢!

有关ShowCaseView的更多信息,这将有所帮助.. https://github.com/amlcurran/Showcaseview

Gio*_*ova 6

我发现了如何做,我们必须在代码中做一些更改.我正在写这个答案,而当前的ShowcaseView版本是5.0

A)scalemultiplier成为orphelin,我们必须重新实现它.

1)打开StandarShowcaseDrawer.java,找到drawShowcase方法并将其修改为:

@Override
    public void drawShowcase(Bitmap buffer, float x, float y, float scaleMultiplier) {
        Canvas bufferCanvas = new Canvas(buffer);
        //[GIOVA]
        //To avoid an infinite exception
        if(scaleMultiplier == 0.0f)
            scaleMultiplier = 0.001f;
        //[/GIOVA]
        //[Original]
            //bufferCanvas.drawCircle(x, y, showcaseRadius, eraserPaint);
        //[/Original]
        //[GIOVA]
            bufferCanvas.drawCircle(x, y, showcaseRadius * scaleMultiplier, eraserPaint);
        //[/GIOVA]
        int halfW = getShowcaseWidth() / 2;
        int halfH = getShowcaseHeight() / 2;
        int left = (int) (x - halfW);
        int top = (int) (y - halfH);
        showcaseDrawable.setBounds(left, top,
                left + getShowcaseWidth(),
                top + getShowcaseHeight());
        showcaseDrawable.draw(bufferCanvas);
    }
Run Code Online (Sandbox Code Playgroud)

注意:请注意我已经放置了一些[GIOVA]和[Original]标签,因此您可以比较更改;)

2)打开NewShowcaseDrawer.java,与上一步相同:

@Override
    public void drawShowcase(Bitmap buffer, float x, float y, float scaleMultiplier) {
        Canvas bufferCanvas = new Canvas(buffer);
        //[GIOVA]
        //To avoid an infinite exception
        if(scaleMultiplier == 0.0f)
            scaleMultiplier = 0.001f;
        //[/GIOVA]
        eraserPaint.setAlpha(ALPHA_60_PERCENT);
        //[Original]
        //bufferCanvas.drawCircle(x, y, outerRadius , eraserPaint);
        //eraserPaint.setAlpha(0);
        //bufferCanvas.drawCircle(x, y, innerRadius , eraserPaint);
        //[/Original]

        //[GIOVA]
        bufferCanvas.drawCircle(x, y, outerRadius * scaleMultiplier, eraserPaint);
        eraserPaint.setAlpha(0);
        bufferCanvas.drawCircle(x, y, innerRadius * scaleMultiplier, eraserPaint);
        //[/GIOVA]
    }
Run Code Online (Sandbox Code Playgroud)

B)现在我们需要能够设置值,我们将向构建器添加一个方法.打开ShowcaseView.java然后找到以下行:

public static class Builder {
Run Code Online (Sandbox Code Playgroud)

在此Builder类中,添加以下方法:

 public Builder setScaleMultiplier(float multiplier){
            showcaseView.setScaleMultiplier(multiplier);
            return this;
        }
Run Code Online (Sandbox Code Playgroud)

如何使用它 :

现在非常简单,在您的活动中,当您使用Builder设置showcaseview时,只需调用setScaleMultiplier即可.

示例:

sv = new ShowcaseView.Builder(this, true)
                .setTarget(target)
                .setContentTitle(getResources().getString(R.string.welcome))
                .setContentText(getResources().getString(R.string.welcomDescription))
                .setStyle(R.style.MyTheme)
                .setScaleMultiplier(0.3f)
                .build();
sv.Show();
Run Code Online (Sandbox Code Playgroud)