简体   繁体   中英

Two or more layouts on the screen

I have some problem. I try to show on the screen background with picture on it. My background is in the

<ImageView
        android:id="@+id/imageView1"
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"
        android:layout_alignParentRight="true"
        android:layout_alignParentBottom="true"
       android:scaleType="fitXY"
        android:src="@drawable/ic_nebo" />

end i show it on the screen

setContentView(R.layout.background);

But my secon picture, that i need to shown is in class extends SurfaceView

  public class GameView extends SurfaceView 
    {
        /**Загружаемая картинка*/
        private Bitmap bmp;

    /**Наше поле рисования*/
    private SurfaceHolder holder;

    //конструктор
    public GameView(Context context) 
    {
          super(context);
          holder = getHolder();
          holder.addCallback(new SurfaceHolder.Callback() 
          {
                 public void surfaceDestroyed(SurfaceHolder holder) 
                 {
                 }

                 @Override
                 public void surfaceCreated(SurfaceHolder holder) 
                 {
                        Canvas canvas = holder.lockCanvas(null);
                        onDraw(canvas);
                        holder.unlockCanvasAndPost(canvas);
                 }

                 @Override
                 public void surfaceChanged(SurfaceHolder holder, int format, int width, int height) 
                 {
                 }
          });
          bmp = BitmapFactory.decodeResource(getResources(), R.drawable.soldat);
    }

    //Рисуем нашу картинку на черном фоне
    protected void onDraw(Canvas canvas) 
    {
          canvas.drawColor(Color.WHITE);
          canvas.drawBitmap(bmp, 10, 10, null);
    }
}

and I try to put it on the screen by

setContentView( new GameView(this));

but I but I already have setContentView method How I can draw this two picture, one from xml file and another from class setContentView in simultaneously?

Get the root View as shown in this post: Get root view from current activity . Then use View.setBackgroundResource() or similar methods from the obtained View

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM