0
我有一個成就對話,並希望這樣的:Programmically RelativeLayout的布點問題
這是我的代碼,每一個成就是一個相對的佈局,並且都包含在的LinearLayout(pnlAchievement) :
RelativeLayout pnlItem = new RelativeLayout(Parent);
pnlItem.setLayoutParams(new LayoutParams(LayoutParams.FILL_PARENT,
LayoutParams.WRAP_CONTENT));
TextView txtItemName = new TextView(Parent);
txtItemName.setText(ACHIEVEMENTS_NAME[i]);
txtItemName.setLayoutParams(new LayoutParams(
LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT));
TextView txtAchived = new TextView(Parent);
txtAchived.setText(Achived[i] ? "Achieved!" : "Not Achieved!");
RelativeLayout.LayoutParams rlpAchived = new RelativeLayout.LayoutParams(
new LayoutParams(LayoutParams.WRAP_CONTENT,
LayoutParams.WRAP_CONTENT));
rlpAchived.addRule(RelativeLayout.ALIGN_PARENT_RIGHT);
rlpAchived.addRule(RelativeLayout.ALIGN_RIGHT, txtItemName.getId());
txtAchived.setLayoutParams(rlpAchived);
TextView txtDescription = new TextView(Parent);
txtDescription.setText(ACHIEVEMENTS_DESCRIPTION[i]);
txtDescription.setHorizontallyScrolling(false);
RelativeLayout.LayoutParams rlpDesc = new RelativeLayout.LayoutParams(
new LayoutParams(LayoutParams.WRAP_CONTENT,
LayoutParams.WRAP_CONTENT));
rlpDesc.addRule(RelativeLayout.ALIGN_BOTTOM, txtItemName.getId());
rlpDesc.addRule(RelativeLayout.ALIGN_PARENT_LEFT);
txtDescription.setLayoutParams(rlpDesc);
pnlItem.addView(txtItemName);
pnlItem.addView(txtAchived);
pnlItem.addView(txtDescription);
pnlAchievement.addView(pnlItem);
它工作得很好列出所有的成績,但說明是不是名字的下方,它是通過名稱,像這樣:
而且,您可以告訴我如何在不使用Canvas的情況下在每個項目之間添加一行(這不是非常重要,但如果有的話,它會更好)?
感謝您的支持。但我改變了以下它也不起作用:( – 2011-05-28 13:30:53
這很奇怪,你可以顯示修改的部分? – Thys 2011-05-28 13:35:53
沒有別的,我只是改變RelativeLayout.ALIGN_BOTTOM爲RelativeLayout.BELOW,結果保持不變!然後,我將rlpDesc的寬度切換到FILL_PARENT,並且它也不會改變任何東西。 – 2011-05-28 13:38:18