I have a ListView
where the rows have a TextView
. In my code I need to know the height
of each row to be able to dynamically calculate the list size. This is the layout used in each row:
<TextView xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/title_subgroup"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:gravity="center"
android:padding="5dp"
android:textSize="18sp"
android:textStyle="bold" />
This is the code I use to get the size in pixels:
float sizeInDip = 10f;
float sizeInSp = 18f;
ROW_HEIGHT = (int) (TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, sizeInDip, getResources().getDisplayMetrics())
+ context.getResources().getDisplayMetrics().scaledDensity * sizeInSp);
The result I got is lower than the real size. With this code ROW_HEIGHT
is 36
, and it should be something like 45
. Why is that difference?
Thanks!