Domanda

Sto cercando di porre due foto una sopra l'altra. Top uno è trasparente. In cima a loro sto cercando di aggiungere una tela trasparente in modo che l'utente può disegnare, tipo, tutto ciò che devono fare e le due immagini in basso sono visibili.

Così posso ottenere le due immagini di presentarsi o semplicemente la tela. Ogni volta che provo a visualizzare la tela sembra che è in a [p delle due immagini che li copre.

Ecco quello che ho finora ..

 public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);        
    setContentView(new MyView(this));

..... some code to set up the paint
}

private Paint       mPaint;
private MaskFilter  mEmboss;
private MaskFilter  mBlur;

public class MyView extends View {

        private static final float MINP = 0.25f;
        private static final float MAXP = 0.75f;

        private Bitmap  mBitmap;
        private Canvas  mCanvas;
        private Path    mPath;
        private Paint   mBitmapPaint;                

        public MyView(Context c) {
            super(c);                       

            // Creating a new relative layout add the definition again.       
            RelativeLayout relativeLayout = new RelativeLayout(TwoPicksOnEachOther.this);                   
            // Setting the orientation to vertical         
            ////relativeLayout.setOrientation(LinearLayout.VERTICAL);                   

            // Creating Fish  image       
            final ImageView iv = new ImageView(TwoPicksOnEachOther.this);         
            iv.setImageResource(R.drawable.fish2);
            // relative layout parameters
            RelativeLayout.LayoutParams lp = new RelativeLayout.LayoutParams(     
                    RelativeLayout.LayoutParams.FILL_PARENT, 
                    RelativeLayout.LayoutParams.FILL_PARENT);        
            //iv.setId(1);                          
            relativeLayout.addView(iv,lp);        

            // Creating transparent image with boat.
            final ImageView iv2 = new ImageView(TwoPicksOnEachOther.this);
            iv2.setImageResource(R.drawable.ctdeasytwo);
            //iv2.setId(2);
            RelativeLayout.LayoutParams lp2 = new RelativeLayout.LayoutParams(     
                    RelativeLayout.LayoutParams.FILL_PARENT, 
                    RelativeLayout.LayoutParams.FILL_PARENT);
            relativeLayout.addView(iv2,lp2);     

            mBitmap = Bitmap.createBitmap(480, 800, Bitmap.Config.ARGB_8888); 
            //mBitmap = BitmapFactory.decodeResource(getResources(),
            //        R.drawable.ctdeasytwo);                      
            mCanvas = new Canvas(mBitmap);
           // mCanvas.drawBitmap(mBitmap, 10, 10, null);
            mPath = new Path();
            mBitmapPaint = new Paint(Paint.DITHER_FLAG);

        }

        @Override
        protected void onDraw(Canvas canvas) {
            canvas.drawColor(Color.TRANSPARENT);

            canvas.drawBitmap(mBitmap, 0, 0, mBitmapPaint);  

            canvas.drawPath(mPath, mPaint);
        }

................... More code to manage touch events.

Ora sto ritenendo sospetto che la tela non è parte del layout relativo. Che potrebbe essere il problema? Se sì, non posso fare relativeLayout.addView (mCanvas, lp);

Qualche suggerimento?

È stato utile?

Soluzione

Siamo spiacenti dovuto aspettare otto ore per rispondere alla mia domanda.

Sono stato in grado di risolvere il problema. Ho creato una classe.

public class newClass extends View { 
public newClass (Context context){ super(context); } 
... 
@Override protected void onDraw(Canvas canvas) { 
canvas.drawColor(Color.TRANSPARENT); } 

Poi tutto quello che dovevo fare

final newClass myCanvas = new newClass (this); 

relativeLayout.addView(myCanvas,lp2); 

funziona bene ...

Altri suggerimenti

Sono riuscito a fare qualcosa di simile (dipingere su una tela trasparente con una bitmap di sfondo dietro di esso) facendo quanto segue (solo alcune parti del codice sono indicati):

public class MyView extends View {
    public MyView(Context c) {
        super(c);
        Bitmap tmpBitmap;

        // Create the background bitmap and convert it to a drawable object
        mBackBitmap = Bitmap.createBitmap(tmpBitmap, 0, 0, tmpBitmap.getWidth(), tmpBitmap.getHeight(), aMatrix, false);
        mBackBitmapDrawable = new BitmapDrawable(mBackBitmap);
        // Set the drawable object as the background
        setBackgroundDrawable(mBackBitmapDrawable);
        // Create an empty bitmap for the canvas
        mBitmap = Bitmap.createBitmap(tmpBitmap.getWidth(), tmpBitmap.getHeight(), Bitmap.Config.ARGB_8888);
        mCanvas = new Canvas(mBitmap);
    }

    @Override
    protected void onDraw(Canvas canvas) {
        //Log.d("MyView", "onDraw");
        // Use transparent background
        canvas.drawColor(Color.TRANSPARENT);
        canvas.drawBitmap(mBitmap, 0, 0, mBitmapPaint);
        canvas.drawPath(mPath, mPaint);
    }
}

La speranza aiuta.

u può fare riferimento questo in Canvas con eventi touch

Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top