Question

Je suis en train de poser deux images sur le dessus de l'autre. Haut est transparent. En plus d'eux, je suis en train d'ajouter une image transparente afin que l'utilisateur peut en tirer, le type, tout ce qu'ils doivent faire et les deux images du bas sont visibles.

Je peux donc obtenir les deux images pour montrer ou simplement la toile. Chaque fois que j'essaie d'afficher la toile, il semble que c'est à [p des deux images couvrant les.

Voici ce que je dois à ce jour ..

 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.

Maintenant, je soupçonnais que la toile ne fait pas partie de la disposition relative. Est-ce que cela pourrait être le problème? Si oui, je ne peux pas faire relativeLayout.addView (mCanvas, lp);

Toutes les suggestions?

Était-ce utile?

La solution

Désolé dû attendre huit heures pour répondre à ma propre question.

Je suis en mesure de résoudre le problème. J'ai créé une classe.

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

Alors tout ce que je devais faire

final newClass myCanvas = new newClass (this); 

relativeLayout.addView(myCanvas,lp2); 

fonctionne très bien ...

Autres conseils

J'ai réussi à faire quelque chose de similaire (peinture sur une toile transparente avec un bitmap de fond derrière elle) en procédant comme suit (seulement les parties du code sont indiqués):

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);
    }
}

it helps.

Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top