例如,這是mButton
:安卓:如何獲得一個視圖的高度
<Button
android:id="@+id/mbtn"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="mButton" />
這是我試圖讓高度:
int height = mButton.getLayoutParams.height;
但是,當我登錄它,它說高度是-2。我認爲這可能是「wrap_content」的整數值。那麼我怎麼才能得到實際的身高?謝謝!