1
我在使用按鈕和圖像時遇到了一些困難。我有兩個按鈕,一個緊挨着另一個,但第二個出現錯誤的圖像。它用一些工具顯示圖像。錯誤的圖像出現在Android的按鈕背景
這裏是我的代碼:
TextView categoriaText = new TextView(this);
RelativeLayout.LayoutParams params = new RelativeLayout.LayoutParams(LayoutParams.FILL_PARENT,
LayoutParams.WRAP_CONTENT);
params.addRule(RelativeLayout.ALIGN_PARENT_LEFT);
// use same id as defined when adding the button
params.addRule(RelativeLayout.LEFT_OF, 1001);
params.topMargin = top;
params.leftMargin = 30;
categoriaText.setLayoutParams(params);
categoriaText.setText(_listaCategorias.get(i).getNome());
categoriaText.setTextSize(20);
Button deleteBtn = new Button(this);
RelativeLayout.LayoutParams params2 = new RelativeLayout.LayoutParams(60,
60);
params2.addRule(RelativeLayout.ALIGN_PARENT_RIGHT);
params2.rightMargin = 80;
params2.topMargin = top;
deleteBtn.setLayoutParams(params2);
deleteBtn.setBackgroundResource(R.drawable.ic_coleccao);
// give the button an id that we know
deleteBtn.setId(1001);
Button editBtn = new Button(this);
RelativeLayout.LayoutParams params3 = new RelativeLayout.LayoutParams(60,
60);
// params2.addRule(RelativeLayout.RIGHT_OF, 1001);
params3.addRule(RelativeLayout.ALIGN_PARENT_RIGHT);
params3.topMargin = top;
editBtn.setLayoutParams(params3);
editBtn.setBackgroundResource(R.drawable.ic_edit);
這裏是一個screenshoot:
第二圖像不正確的。
您的問題與您發佈的代碼無關。畢竟你的問題是在圖像名稱中,而不是代碼本身。 – 2011-12-30 14:51:48
嘗試(Eclipse菜單)*項目>清潔* – 2011-12-30 15:46:36
謝謝大家。 – 2011-12-30 16:29:33