是否可以在ShowCaseView中更改圆圈的当前大小?
我的代码中包含以下内容:
ShowcaseView.ConfigOptions co = new ShowcaseView.ConfigOptions();
co.hideOnClickOutside = false;
return ShowcaseView.insertShowcaseView(id, activity, title, message, co);
但是现在,我只是显示ShowCaseView的默认大小,如果是这样我该如何调整大小呢?
谢谢!
有关ShowCaseView的更多信息,这将有所帮助.. https://github.com/amlcurran/Showcaseview
答案 0 :(得分: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);
}
注意:请注意我已经放置了一些[GIOVA]和[原始]标签,因此您可以比较更改;)
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]
}
B)现在我们需要能够设置值,我们将向构建器添加方法。 打开ShowcaseView.java然后找到以下行:
public static class Builder {
在此Builder类中,添加以下方法:
public Builder setScaleMultiplier(float multiplier){
showcaseView.setScaleMultiplier(multiplier);
return this;
}
如何使用
现在非常简单,在您的活动中,当您使用Builder设置展示视图时,只需调用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();
答案 1 :(得分:3)
使用setScaleMultiplier(float scaleMultiplier)
希望能帮到你!