0

答えが見つからなかった別の質問: RelativeLayout があり、右端にボタンがあり、左端に ImageButton があるはずです。そして、私はこれを整理する方法がわかりません。

私が試しているのは:

    RelativeLayout TopLayout = (RelativeLayout) findViewById(R.id.topLayout);
    TopLayout.removeAllViews();
    TopLayout.setPadding(m_TableRowPadding_px, 8, m_TableRowPadding_px, 4);

    RelativeLayout.LayoutParams bParams = new RelativeLayout.LayoutParams(m_Resources
        .getDimensionPixelSize(R.dimen.ButtonWidth), m_DefaultButtonHeight_px);
    bParams.addRule(RelativeLayout.ALIGN_PARENT_RIGHT);
    bParams.addRule(RelativeLayout.ALIGN_PARENT_TOP);

    Button itemAddButton = new Button(this);
    itemAddButton.setLayoutParams(bParams);
    itemAddButton.setText(m_Resources.getString(R.string.add_item_button));
    itemAddButton.setOnClickListener(new View.OnClickListener()
    {...});

    TopLayout.addView(itemAddButton);

    RelativeLayout.LayoutParams ibParams = new RelativeLayout.LayoutParams(MIN_IMG_BUTTON_WIDTH,
        m_DefaultButtonHeight_px);
    ibParams.addRule(RelativeLayout.LEFT_OF, itemAddButton.getId());

    ImageButton speechButton = new ImageButton(this);

    speechButton.setLayoutParams(ibParams);
    speechButton.setContentDescription(m_Resources.getString(R.string.AddSpeechItemString));
    speechButton.setOnClickListener(new View.OnClickListener()
    {... });
    speechButton.setImageDrawable(m_Resources.getDrawable(R.drawable.micro2));

    TopLayout.addView(speechButton);

  }

しかし、結果として、(必要に応じて) 右側にボタンが表示され、左側に ImageButton が表示されます。:(

誰でも私を助けることができますか?うーん

乾杯

クリス

4

2 に答える 2

4

行を使用する前に、itemAddButtonボタンにIDを設定する必要があります。現在、itemAddButton.getId()は-1を返します。

ibParams.addRule(RelativeLayout.LEFT_OF, itemAddButton.getId());

あなたは次のようなものを設定することができます

itemAddButton.setId(5005000);
于 2012-07-18T21:36:56.533 に答える
0

にルールを追加してみてくださいspeechButton

ibParams.addRule(RelativeLayout.ALIGN_TOP, itemAddButton.getId());

RelativeLayout.ALIGN_BOTTOMそれがあなたにとってよりうまくいくなら、あなたはまた使うことができます。

于 2012-07-18T21:39:03.890 に答える