我試圖建立一個RPN計算器添加視圖,直到有沒有更多的空間
鍵盤收縮和拉伸相當好,所以我想棧行添加到視圖(藍色選擇)
3: 0
2: 0
1: 0
直到屏幕/視圖沒有更多空間。
第一行的xml,它的容器是。
<LinearLayout
android:id="@+id/stackLayout"
android:layout_width="fill_parent"
android:layout_height="0dp"
android:layout_gravity="bottom|fill_vertical"
android:layout_weight="1"
android:gravity="bottom"
android:orientation="vertical" >
<!-- Stack row -->
<LinearLayout
android:id="@+id/stackRow"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:gravity="bottom"
>
<!-- Row index -->
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="1:"
style="@style/text_style" />
<!-- Value -->
<TextView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:gravity="center_vertical|right"
android:singleLine="true"
android:text="0"
style="@style/text_style" />
</LinearLayout>
</LinearLayout>
我在嘗試添加元素失敗的嘗試是在activitys的OnCreate
// Setup table rows for value stack
LinearLayout stackView = (LinearLayout) findViewById(R.id.stackLayout);
int heightPx = stackView.getHeight();
LinearLayout stackRow = (LinearLayout) findViewById(R.id.stackRow);
int rowHeightPx = stackRow.getHeight();
// Space for additional rows
int heightLeftPx = heightPx - rowHeightPx;
//stackView.removeView(stackRow);
// Add rows to fit
int count = 0;
while (heightLeftPx > rowHeightPx) {
count++;
// add new LinearLayout row
heightLeftPx-= rowHeightPx;
}
的stackView不斷報告其爲0一樣的行高。 我哪裏錯了?
我已經嘗試將此移至onStart,onResume和onPostResume以獲得相同的結果。
它們在OnCreate,OnStart和OnResume中產生0。 – 2012-02-19 20:15:03