我有一个具有以下Views视图结构的游戏应用程序。首先我有一个空的FrameLayout像这样:SurfaceHolder.setFormat(PixelFormat.RGBA_8888)在某些设备上失败,而不是其他设备
FrameLayout game_frame_layout = new FrameLayout(getApplicationContext());
然后我两个视图添加到它,像这样:
game_frame_layout.addView(customView);
game_frame_layout.addView(butView);
的customView是用于显示各种移动游戏显卡的同时butView显示一些ImageButtons在移动图形的顶部。 customView是扩展SurfaceView的类CustomView的一个实例。
CustomView包括以下代码
void updateView()
{
final SurfaceHolder holder = getHolder();
holder.setFormat(PixelFormat.RGBA_8888);
try
{
Canvas canvas = holder.lockCanvas();
if (canvas != null)
{
onDraw(canvas);
holder.unlockCanvasAndPost(canvas);
}
}
catch (Exception e)
{
e.printStackTrace();
}
}
线holder.setFormat(PixelFormat.RGBA_8888);
是最近添加(见here)。如果没有这一行,我的动画图形显示为颜色太少的格式(实验中我推测它是“RGB_565”),所以我得到了一些banding工件。当我添加setFormat线时,图形在我的三星Galaxy Tab 10.1(Android 3.1)上显示完美(没有条带)...但在另外三个设备上:三星GT-l9100(4.1.2),Nexus 7 ME370T 4.4 .2和HTC One X 4.2.2我只看到与黑色背景对应的按钮。日志中没有指示程序崩溃。
任何想法?
您是否需要该表面的透明度,或者您是否还可以给“PixelFormat.RGB_888”一个镜头? – tiguchi
你的按钮还在你的“黑色”移动图形上移动吗? –