Android : How to Draw multiple images inside the same imageview but shifted in the y coordinate?

StackOverflow https://stackoverflow.com/questions/22403140

  •  14-06-2023
  •  | 
  •  

سؤال

In my android application I have a horizontal list view and a vertical one. The vertical view contains images. When any of the images is touched, it must go to the horizontal view, but every 3 of them must be drawn over each other in the same image view and shifted upwards so that all the images will appear.

Thanks

هل كانت مفيدة؟

المحلول

use this code for show 2 image in one image:

    ImageView myImageView = (ImageView) findViewById(R.id.img1);
    Bitmap bitmap1 = BitmapFactory.decodeResource(getResources(), R.drawable.call);
    Bitmap bitmap2 = BitmapFactory.decodeResource(getResources(), R.drawable.available);
    Bitmap combinedBitmap = getCombinedBitmap(pic2, pic1);

    myImageView.setImageBitmap(b);

and this is the getCombinedBitmap() method :

public Bitmap getCombinedBitmap(Bitmap b, Bitmap b2) {
    Bitmap drawnBitmap = null;

    try {
        drawnBitmap = Bitmap.createBitmap(200, 200, Config.ARGB_8888);

        Canvas canvas = new Canvas(drawnBitmap);
        // JUST CHANGE TO DIFFERENT Bitmaps and coordinates .
        canvas.drawBitmap(b, 0, 0, null);
        canvas.drawBitmap(b2, 0, 0, null);
        //for more images :
        // canvas.drawBitmap(b3, 0, 0, null);
        // canvas.drawBitmap(b4, 0, 0, null);

    }
    catch (Exception e) {
        e.printStackTrace();
    }
    return drawnBitmap;
}

enjoy :)

مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top