ShowcaseView - width and height must be > 0

岁酱吖の 提交于 2019-11-28 13:59:31

This is a known issue : Github issues when updateBitmap() is called too early.
This issue comes from Bitmap.createBitmap() method either width or height equals to 0.
A workaround is to delay the ShowcaseView creation more:

someView.post(new Runnable() {
    @Override
    public void run() {
        // display ShowcaseView here
    }
});

You could also change the updateBitmap() method from the library to not create the bitmap if the view width or height is wrong.

Wessel du Plooy

Had the same problem, and posted my solution in another thread: https://stackoverflow.com/a/25521608/1752670

I changed the ShowcaseView class slightly

go to com.github.amlcurran.showcaseview.ShowcaseView and change this method

private void updateBitmap() {
        if ((bitmapBuffer == null || haveBoundsChanged()) && getMeasuredHeight() > 0 && getMeasuredWidth() > 0) {
            if(bitmapBuffer != null)
                bitmapBuffer.recycle();
            int width = getMeasuredWidth();
            int height = getMeasuredHeight();
            if(width > 0 && height > 0)
                bitmapBuffer = Bitmap.createBitmap(width, height, Bitmap.Config.ARGB_8888);

        }
    }

This was a bug in ShowcaseView, and was fixed starting in v5.4.2: https://github.com/amlcurran/ShowcaseView/commit/c79c60dc798f081fb62e48c549c7bdbff8da51b9

So, you can just update your build.gradle to:

compile 'com.github.amlcurran.showcaseview:library:5.4.2'

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!