另一个我找不到答案的问题:我有一个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。:(
有人可以帮我吗?哦
干杯
克里斯