poponotan
unread,May 19, 2011, 5:03:34 PM5/19/11Sign in to reply to author
Sign in to forward
You do not have permission to delete messages in this group
Either email addresses are anonymous for this group or you need the view member email addresses permission to view the original message
to 日本Androidの会
はじめまして、ぽぽのたんと申します
最近Androidの開発を始めたのですが、躓いてしまったのでご相談させてください。
FrameLayout内に、複数のSurfaceViewを重ねて表示したいのですが、レイヤーの表示順が入れ替わってしまい困っております。
以下のサンプルで試したところ、初期状態での背景色は赤ですが、onPauseが呼ばれたタイミングで青になってしまいます。
onResumeでred.bringToFront();とかやってみたにですが、効果がありませんでした。
どなかたお知恵をお貸しいただければ幸いです。
よろしくお願いいたします。
public class Test extends Activity {
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
View red = new ColorSurfaceView(this, Color.RED);
View blue = new ColorSurfaceView(this, Color.BLUE);
FrameLayout frame = (FrameLayout) findViewById(R.id.frameLayout1);
frame.addView(red);
frame.addView(blue);
}
class ColorSurfaceView extends SurfaceView implements Callback {
int color;
public ColorSurfaceView(Context context, int color) {
super(context);
this.color = color;
getHolder().addCallback(this);
}
@Override
public void surfaceChanged(SurfaceHolder arg0, int arg1, int arg2,
int arg3) {
Canvas canvas = getHolder().lockCanvas();
canvas.drawColor(color);
getHolder().unlockCanvasAndPost(canvas);
}
@Override
public void surfaceCreated(SurfaceHolder arg0) {
}
@Override
public void surfaceDestroyed(SurfaceHolder arg0) {
}
}
}