I have an ImageView with height set to 120dp. When I get the view.height it equalls to 360, why won't it be equal to 120?
I'm not sure of the code won't be of help but:
<ImageView
android:id="@+id/profilePic1"
android:layout_width="120dp"
android:layout_height="120dp"
android:scaleType="centerCrop"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
android:clickable="true"
app:srcCompat="@drawable/profile_pic1"/>
Activity:
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
val layoutInflater: LayoutInflater = LayoutInflater.from(this)
val view: View = layoutInflater.inflate(R.layout.activity_edit_profile, null)
view.viewTreeObserver.addOnGlobalLayoutListener(object: ViewTreeObserver.OnGlobalLayoutListener {
override fun onGlobalLayout() {
// remove listener
view.viewTreeObserver.removeOnGlobalLayoutListener(this)
// insert coordinates (coor) of each image to imagePosition variables
Log.d("TAG", profilePic1.height.toString()) // RETURNS 360
}
})