Android中按钮背景出现错误图像
我在使用按钮和图像时遇到了一些困难。我有两个按钮,一个挨着另一个,但第二个按钮显示错误的图像。它显示了一个带有一些工具的图像 这是我的密码:Android中按钮背景出现错误图像,android,android-layout,Android,Android Layout,我在使用按钮和图像时遇到了一些困难。我有两个按钮,一个挨着另一个,但第二个按钮显示错误的图像。它显示了一个带有一些工具的图像 这是我的密码: TextView categoriaText = new TextView(this); RelativeLayout.LayoutParams params = new RelativeLayout.LayoutParams(LayoutParams.FILL_PARENT, LayoutParams.WRAP_CONTEN
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);
以下是一个截图:
第二个映像不正确。更常见的情况是,对R类中资源的引用变得混乱。
如果您是在eclipse中开发的,请销毁生成的R类,并让它通过重新启动eclipse自动重建自身。对R类中资源的引用变得混乱的情况更常见。
如果您是在eclipse中开发的,请销毁生成的R类,并让它通过重新启动eclipse自动重建自身。您的问题与您发布的代码无关。毕竟你的问题出在图像名称上,而不是代码本身。try(Eclipse菜单)Project>clean你的问题与你发布的代码无关。毕竟,问题出在图像名称上,而不是代码本身。try(Eclipse菜单)Project>Clean