blazsolar / HorizontalPicker

Android widget allowing user to select one item from set of them by swiping left and right.
http://blaz.solar/HorizontalPicker
Apache License 2.0
228 stars 81 forks source link

Boring Layouts do not show up when placed inside a ScrollView #40

Closed ArcherN9 closed 4 years ago

ArcherN9 commented 8 years ago

The BoringLayout does not show up when the HorizontalPicker view is placed inside a ScrollView. It works flawlessly when the same is implemented elsewhere though. There's no exception thrown, and there are no call backs triggered when items are selected.

blazsolar commented 8 years ago

Just the boring layout or the whole view? I believe it could be issue with height of the view. Will look into it.

ArcherN9 commented 8 years ago

@blazsolar Just the boring layouts. Yes, the issue is with the height of the elements. I did a dirty fix on this. unsure atm if it'll break something else.

@Override protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {

    int heightMode = MeasureSpec.getMode(heightMeasureSpec);
    int width = MeasureSpec.getSize(widthMeasureSpec);
    int heightSize = MeasureSpec.getSize(heightMeasureSpec);

    int height;
    if(heightMode == MeasureSpec.EXACTLY) {
        height = heightSize;
    } else {
        Paint.FontMetrics fontMetrics = mTextPaint.getFontMetrics();
        int heightText = (int) (Math.abs(fontMetrics.ascent) + Math.abs(fontMetrics.descent));
        heightText += getPaddingTop() + getPaddingBottom();
        //height = Math.min(heightSize, heightText);
        //Changed the above Math.min() to Math.max() since `heightSize` is always 0 in ScrollView. Hence, the height is always 0 being the closest value to negative infinity (Math.min functionality.)
        height = Math.max(heightSize, heightText);
    }

    setMeasuredDimension(width, height);
}