Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8581533
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T21:04:33+00:00 2026-06-11T21:04:33+00:00

I have two ImageViews. ImageView1 is a background image and ImageView2 is a smaller

  • 0

I have two ImageViews. ImageView1 is a background image and ImageView2 is a smaller image. The position of the ImageView2 is somewhere in the middle of the application.

I would like to combine those two ImageView into a bitmap so that ImageView2 is on top of ImageView1.

The combine process works fine but ImageView2 is always on the top left corner of the bmp file.

Below is my code that I used to generate the bmp:

    ImageView iv = (ImageView)findViewById(R.id.imageView1);
    ImageView iv2 = (ImageView)findViewById(R.id.imageView2);

    File rootPath = new File(Environment.getExternalStorageDirectory(), "testmerge");

    if (!rootPath.exists()) {
        rootPath.mkdirs();
    }

    Toast.makeText(this, rootPath.getPath(), Toast.LENGTH_LONG).show();
    File dataFile = new File(rootPath, "picture.png");

    iv.measure(MeasureSpec.makeMeasureSpec(0, MeasureSpec.UNSPECIFIED), MeasureSpec.makeMeasureSpec(0, MeasureSpec.UNSPECIFIED));
    iv.layout(0, 0, iv.getMeasuredWidth(), iv.getMeasuredHeight());

    iv.setDrawingCacheEnabled(true);
    Bitmap b1 = Bitmap.createBitmap(iv.getDrawingCache());
    iv.setDrawingCacheEnabled(false);

    iv2.measure(MeasureSpec.makeMeasureSpec(0, MeasureSpec.UNSPECIFIED), MeasureSpec.makeMeasureSpec(0, MeasureSpec.UNSPECIFIED));
    iv2.layout(0, 0, iv2.getMeasuredWidth(), iv2.getMeasuredHeight());

    iv2.setDrawingCacheEnabled(true);
    Bitmap b2 = Bitmap.createBitmap(iv2.getDrawingCache());
    iv2.setDrawingCacheEnabled(false);        

    Bitmap bmOverlay = Bitmap.createBitmap(b1.getWidth(), b1.getHeight(), b1.getConfig());
    Canvas canvas = new Canvas(bmOverlay);
    Paint paint = new Paint();
    paint.setAntiAlias(true);
    paint.setFilterBitmap(true);
    paint.setDither(true);

    canvas.drawBitmap(b1, 0, 0, null);
    canvas.drawBitmap(b2, 0, 0, null);

    try {
        FileOutputStream out = new FileOutputStream(dataFile, false);
        bmOverlay.compress(CompressFormat.PNG, 95, out);
    } catch (IOException e) {
        e.printStackTrace();
    }

Can you tell me how can I adjust the position of the final bitmap file so that the ImageViews will be in the same position as it display on the app?

Thanks.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-11T21:04:34+00:00Added an answer on June 11, 2026 at 9:04 pm

    just create a FrameLayout, and include two ImageViews within it. it will naturally overlay the first image with the second.

    <FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
        android:layout_width="fill_parent"
        android:layout_height="fill_parent" >
    
        <ImageView
            android:id="@+id/main_image"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:src="@drawable/main" />
    
        <ImageView
            android:id="@+id/overlay_image"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:src="@drawable/overlay" />
    
    </FrameLayout>
    

    you can apply gravities to center or otherwise align the images.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a ImageView, and I would like the picture to switch between two
i have 20 imageviews with background image set. When user clicks on one image
In my application i have two images original upper image and down reflection one.
I have two ImageViews, one called imageView and the other called subView (which is
I have a activity where I have two imageViews. In onTouch I recognize which
I have a big problem. I have a activity where I have two imageViews.
I have created two imageViews promatically as shown below: public void createImageViews(Integer count){ ImageView[]
I have a layout that contains two ImageViews. I want one of them to
My storyboard seems locked. I have added new labels and imageviews to two different
In my xml file, I have declared two imageview and later I add image

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.