另一個問題,我找不到答案: 我有一個RelativeLayout,它應該有一個按鈕在其右邊緣和一個ImageButton靠近左邊。我不知道如何安排這一點。Android:RelativeLayout.LEFT_OF不起作用?
我嘗試是:
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到左側的按鈕。 :(
誰能幫我?哦哦
乾杯
克里斯
謝謝:) 從來沒有想過,該ID必須由程序員設置:( – 2012-07-19 06:39:24