I know this question has been asked a lot. But he answers does not work for me.
Here is a simple textView :
<TextView
android:id="@+id/cardText"
android:layout_width="240dp"
android:layout_height="wrap_content"
android:layout_marginEnd="30dp"
android:layout_marginStart="30dp"
android:layout_marginTop="60dp"
android:background="@color/transparent"
android:padding="0dp"
android:paddingBottom="0dp"
android:paddingEnd="0dp"
android:paddingStart="0dp"
android:paddingTop="0dp"
android:text="hello world"
android:textSize="36sp"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
In my main activity, I get it that way : final TextView cardNumber = (TextView) findViewById( R.id.cardNumber );
And the I try to measure.
int ww = cardText.getMeasuredWidth();
int hh = cardText.getMeasuredHeight();
Log.v("ww", String.valueOf(ww) ); // => 630
Log.v("hh", String.valueOf(hh) ); // => 127
=> WTF
I can also try to make some constraints on the measurements :
cardText.measure(View.MeasureSpec.makeMeasureSpec( 240, View.MeasureSpec.EXACTLY), 0);
int ww = cardText.getMeasuredWidth();
int hh = cardText.getMeasuredHeight();
Log.v("ww", String.valueOf(ww) ); // => 240
Log.v("hh", String.valueOf(hh) ); // => 238
This one makes a little bit more sense for the with. But what about the height.
I tried at lot of weird combinaison but I cannot manage to get the height of my text view.
The measure is made on a button click ; so there is no creation state issue.
(the end goal is to auto fit my text ; I found some libraries, but they autofit only in with)