我有一个奇怪的问题——当方向设置为垂直时我看到按钮——但当设置为水平时它们消失了。它们也没有宽度、高度或底部。他们只是不存在。都是因为横。我能做些什么?这是代码:
private void addViews(int addAnotherColor)
{
if (buttonView != null)
{
buttonView.removeAllViews();
}
buttonView = new LinearLayout(this);
buttonView.setOrientation(LinearLayout.HORIZONTAL);
buttonView.setId(3);
try
{
InputStream deleteImage = getAssets().open("delete.bmp");
InputStream fewColorsImage = getAssets().open("fewColors.bmp");
InputStream doNotHillImage = getAssets().open("doNotHill.bmp");
InputStream pauseImage = getAssets().open("pause.bmp");
InputStream elusiveColor = getAssets().open("elusive.bmp");
fewColors.setImageBitmap(BitmapFactory.decodeStream(fewColorsImage));
elusive.setImageBitmap(BitmapFactory.decodeStream(elusiveColor));
hillIt.setImageBitmap(BitmapFactory.decodeStream(doNotHillImage));
delete.setImageBitmap(BitmapFactory.decodeStream(deleteImage));
pause.setImageBitmap(BitmapFactory.decodeStream(pauseImage));
}
catch (IOException e)
{
// TODO Auto-generated catch block
e.printStackTrace();
}
buttonView.addView(pause, 70, 60);
buttonView.addView(delete, 100, 60);
buttonView.addView(randomColor, 150, 60);
buttonView.addView(fewColors, 192, 60);
buttonView.addView(hillIt, 120, 60);
buttonView.addView(elusive, 150, 60);
menuView.addView(buttonView);
}