2012-02-19 1 views
-1

がなくなるまで、私はRPN電卓(キーボードが縮小し、非常によく伸びるので、私はビューにスタック行を追加したいと思い、それ以上の部屋

enter image description here

を構築しようとしているブルーのビューを追加します選択)

3:  0 
2:  0 
1:  0 

画面/ビューに空きがなくなるまで、

最初の行のxmlで、そのコンテナはです。 activitysが

// 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; 
} 

をOnCreate関数で要素を追加しようとしているの

<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> 

私の失敗した試みはstackViewが行と同様に0として、その高さを報告し続けています。 どこが間違っていますか?

これをonStart、onResume、onPostResumeに同じ結果で移動しようとしました。

答えて

0

私は自分のアクティビティのonCreateに追加する必要:

class AnInnerSillyWaitToCompleteLayoutClass extends AsyncTask<Void, Void, Void> 
    protected Void doInBackground(Void... voids) { 
     sleep a little while 

    protected void onPostExecute(Void result) { 
     Here the layout is complete and the dynamic 
     dimensions can be calculated. 

編集:適切な方法は、レイアウトの変更をリッスンすることであり、これらを実装

new AnInnerSillyWaitToCompleteLayoutClass().execute((Void[]) null); 

はその後、私の活動に私が持っていましたレイアウト完了後のアクション。

0

私の知る限り、ビューはまだ作成されていません。多分彼らは再開しているのでしょうか?

+0

OnCreate、OnStart、OnResumeで0を返します。 –

関連する問題