我正在尝试在GLSurfaceView上添加ImageButton。添加带文本的常规按钮已经完成并显示在我的平板电脑上。创建一个ImageButton只能工作一半。当我以编程方式创建我的ImageButton时,它只显示按钮的框,但不会加载基本的android图标。这是我的代码:
LinearLayout btnLO = new LinearLayout(this);
LinearLayout.LayoutParams paramsLO = new LinearLayout.LayoutParams(
LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT);
// button margins
paramsLO.setMargins(0, 0, 0, 0);
// button height/width *pixels*
paramsLO.height = 75;
paramsLO.width = 75;
btnLO.setOrientation(LinearLayout.VERTICAL);
btnLO.setBackgroundColor(5); // not working correctly
//buttons
Button b1 = new Button(this);
Button b2 = new Button(this);
Button b3 = new Button(this);
int i1Btn = 0;
ImageButton i1 = new ImageButton(this);
i1Btn = R.drawable.icon;
i1.setImageResource(i1Btn);
//text for buttons
b1.setText("Arrow");
b2.setText("Move");
b3.setText("Scale");
//displays buttons with parameters (if any)
btnLO.addView(b1, paramsLO);
btnLO.addView(b2, paramsLO);
btnLO.addView(b3, paramsLO);
btnLO.addView(i1, paramsLO);
btnLO.setGravity(Gravity.LEFT | Gravity.CENTER_HORIZONTAL);
this.addContentView(btnLO, new LayoutParams(LayoutParams.FILL_PARENT,
LayoutParams.FILL_PARENT));
同样,b1-b3是常规按钮,上面有文字。他们工作得很好。但是“il”ImageButton只显示没有图标的按钮部分。关于我缺少什么的任何建议?