我正在尝试在 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 只显示没有图标的按钮部分。关于我所缺少的任何建议?