In my program, I extensively use weight components, adjusting the text of the buttons using a small function using paint.getTextBounds . My function is looking for the size of the text that fits into the borders of the button. In this function, I pass the container and the text, where the measurements take place like this:
paint.setTypeface(typeface); paint.getTextBounds(text, 0, text.length(), textRect); int cWidth = container.getMinimumWidth(); int cHeight = container.getMinimumHeight(); int tWidth = textRect.width(); int tHeight = textRect.height(); if ((tWidth>cWidth)||(tHeight>cHeight)){ //ัะตะบัั ะฝะต ะฒะปะตะท } else { //ัะตะบัั ะฒะปะตะท } On the emulator with a small screen size, I got a few buttons
mMinHeight = 168 mMeasuredHeight = 102 accordingly, the text size is chosen too large for the component. But at the time of the creation of the button mMesauredHeight does not exist yet, more precisely equal to 0. Therefore, I used getMinimumHeight . The approach through MinHeight obviously does not work for small screens. I look towards onMeasure and onLayout.
Actually, how else can we find out the size of the components at the time of their creation? Maybe there is another simple way to adjust the text to the size of the view?