我嘗試獲取線性佈局的大小。我總是得到iactualHeight = 0下面的代碼:如何獲得線性佈局的大小
li=(LinearLayout)findViewById(R.id.textviewerbuttonlayout);
li.requestLayout();
int iactualHeight=li.getLayoutParams().height;
我的佈局定義如下:
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_height="fill_parent"
android:layout_width="fill_parent"
android:background="#FFFFFF"
android:id="@+id/textviewerlayout"
android:orientation="vertical">
<WebView
android:id="@+id/mywebview"
android:layout_width="fill_parent"
android:layout_height="0dp"
android:layout_weight="22" />
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/textviewerbuttonlayout"
android:layout_width="fill_parent"
android:layout_height="0dp"
android:layout_weight="2"
android:background="#FFFFFF"
android:orientation="horizontal" >
.... BUTTONS .....
</LinearLayout>
</LinearLayout>
有人什麼想法?
謝謝。在onStart我仍然得到0.在OnGlobalLayoutListener我得到正確的值。所以你的快速答案是非常有用的。 –