gelitenight / WaveView

waveview for android
Apache License 2.0
1.59k stars 325 forks source link

when using wave animation #8

Closed sonaypsi closed 7 years ago

sonaypsi commented 8 years ago

java.lang.IllegalArgumentException: width and height must be > 0 in wave annimation

gelitenight commented 8 years ago

@sonaypsi Please show me more detail, such as the layout xml and java code.

jmrboosties commented 7 years ago

I noticed the issue when trying to set a wave color. It tries to recreate the shader, but if you call the method before the view is drawn it will throw the error that person mentioned. I changed the method to look like this and it worked:

public void setWaveColor(int behindWaveColor, int frontWaveColor) {
    mBehindWaveColor = behindWaveColor;
    mFrontWaveColor = frontWaveColor;

    // need to recreate shader when color changed
    mWaveShader = null;

    if(getWidth() == 0 || getHeight() == 0) {
        getViewTreeObserver().addOnGlobalLayoutListener(new ViewTreeObserver.OnGlobalLayoutListener() {

            @Override
            public void onGlobalLayout() {
                createShader();
                invalidate();

                getViewTreeObserver().removeOnGlobalLayoutListener(this);
            }

        });
    }
    else {
        createShader();
        invalidate();
    }
}
gelitenight commented 7 years ago

fixed