2011-12-30 46 views
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: Screen Shot

第二圖像不正確的。

+0

您的問題與您發佈的代碼無關。畢竟你的問題是在圖像名稱中,而不是代碼本身。 – 2011-12-30 14:51:48

+1

嘗試(Eclipse菜單)*項目>清潔* – 2011-12-30 15:46:36

+0

謝謝大家。 – 2011-12-30 16:29:33

回答

1

在R類中對資源的引用變得更加混亂。 如果你在eclipse中開發,銷燬生成的R類並讓它通過重新啓動eclipse自動重建。