Custom viewer using screen height even when layout_height is set to wrap_content

I created an object that expands android.view.View, redefining draw()and displaying it on the screen. To put you in the picture, this is a mapping of numbers to represent a game score. It is displayed correctly horizontally, but it raises the entire height of the screen - pressing all the other elements on the screen.

I put layout_height="wrap_content"in the xml, but has no effect.

Does anyone know what I'm doing wrong?

+3
source share
1 answer

I get it...

I had to override onDraw (), but that didn't cause a problem.

, onMeasure() :

@Override
protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
    setMeasuredDimension(DIGIT_WIDTH * getNumberOfDigits(), DIGIT_HEIGHT);
}

DIGIT_WIDTH DIGIT_HEIGHT - , , . getNumberOfDigits() xml.

, - .

+5

Source: https://habr.com/ru/post/1758360/


All Articles