【发布时间】:2020-04-16 12:17:08
【问题描述】:
我有一个高度设置为 120dp 的 ImageView。当我得到 view.height 等于 360 时,为什么不等于 120?
我不确定代码是否有帮助,但是:
<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"/>
活动:
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
}
})
【问题讨论】: