1

すべての表示要素が動的に追加されたアクティビティがあります。活動のためのxmlはまったくありません。

アクティビティは、次のコントロールで構成されています。

  1. RelativeLayout (すべての子ビューが配置されるレイアウト オブジェクト)
  2. TextView (ページのタイトル、RelativeLayout の上部に配置)
  3. ScrollView (すべてのデータ コントロールを保持するスクロール可能な領域)
  4. LinearLayout (アクティビティ ボタンを保持するレイアウト オブジェクト)

ScrollView が Title TextView の下にあり、LinearLayout がアクティビティ ページの下部に設定されている LinearLayout ボタン ホルダーの上にあることを定義する方法を知りたい

RelativeLayout.LayoutParams を使用してルールを設定しようとしましたが、その方法を理解できないようです。ヘルプやチュートリアルへのリンクは高く評価されます

誰かが助けてくれるかどうかを確認するためにコードを含めました

    // declare the items for display
    RelativeLayout baseLayout = new RelativeLayout(this);   
    // add the customer name and number field.
    // NOTE: We will always require this widget regardless of dialog design fields
    tvCustomerNameNumber = new TextView(this);
    tvCustomerNameNumber.setTextSize(20);
    tvCustomerNameNumber.setText("Customer Name & Number");

    // build up the linear layout of controls
    LinearLayout ll = new LinearLayout(this);
    ll.setOrientation(LinearLayout.VERTICAL);       

    // Scroll view.
    // NOTE: We will always need this widget to enable us to scroll the page
    // if too many items are added for the display size
    ScrollView sv = new ScrollView(this);
    sv.addView(ll);

    // buttons
    LinearLayout buttons = new LinearLayout(this);
    buttons.setOrientation(LinearLayout.HORIZONTAL);

    // button edit
    Button edit = new Button(this);
    edit.setId(EDIT_BUTTON_ID);

    // button save
    Button save = new Button(this);
    save.setId(SAVE_BUTTON_ID);

    // button cancel
    Button cancel = new Button(this);
    cancel.setId(CANCEL_BUTTON_ID);

    // add each button to the button layout
    buttons.addView(edit);
    buttons.addView(save);
    buttons.addView(cancel);

    // Scroll view Layout parameters
    RelativeLayout.LayoutParams scrollParams = new RelativeLayout.LayoutParams(LayoutParams.FILL_PARENT, LayoutParams.FILL_PARENT);
    scrollParams.addRule(RelativeLayout.BELOW, tvCustomerNameNumber.getId());
    scrollParams.addRule(RelativeLayout.ABOVE, buttons.getId());

    // buttons Layout parameters
    RelativeLayout.LayoutParams buttonParams = new RelativeLayout.LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT);
    buttonParams.addRule(RelativeLayout.ALIGN_PARENT_BOTTOM);
    buttonParams.addRule(RelativeLayout.BELOW, sv.getId());

    // add the customer name number field to the base layout
    baseLayout.addView(tvCustomerNameNumber);
    // add the scroll view to the base layout
    baseLayout.addView(sv); //, scrollParams);      
    // add the buttons to the base layout
    baseLayout.addView(buttons, buttonParams);

    // set the content view
    this.setContentView(baseLayout);
4

2 に答える 2

1

これを達成するのに役立つ可能性がある以下のリンクを参照してください。

プログラムによる相対レイアウトへのアイテムの追加

プログラムで複数の LinearLayouts を 1 つのビューに追加してから、ViewFlipper に追加する方法は?

于 2012-02-28T12:54:30.317 に答える
1

Deva はすでにあなたの質問に答えていますが、上記のように xml レイアウトを定義し、それを膨張させ、プログラムで動的に入力できるように思えます...おそらく、レイアウトには最初は空の LinearLayout が含まれているか、テキストが含まれていません。 TextView に設定し、すべてを android:visibility="gone" に設定して、すべてのビューを追加/更新したときに表示することもできますか?

于 2012-02-28T13:32:25.800 に答える