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 6596531
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T18:05:18+00:00 2026-05-25T18:05:18+00:00

I have an image to display via an ImageView element. Based on user input

  • 0

I have an image to display via an ImageView element. Based on user input (say, a long press) I will want to overlay something on that image, such that the overlay is in the middle of the screen (or somewhere other than the upper-left corner at least… but the key is that it overlays the image and that I can choose that location in code. It might be an informative TextView item (not a Toast though), or some ephemeral zoom buttons).

This will all eventually be a child of a ScrollView of some kind (likely TwoDScrollView, but if you have a better suggestion let me know), so whatever text or button gets put up should not exclude that possibility. WebView is not an option though. I’d probably use a RelativeLayout unless you have a better suggestion.

I want to do this programmatically – not in XML. I don’t expect a full program from anyone (unless one already exists… I haven’t found one yet though). I just need a solid outline of how to make this happen properly for some text over an image.

Edit: I’ve been looking all day and I’ve found many ideas but they are either XML-only or completely different than what I’m trying to do here. If, however, you have a pointer to something appropriate please let me know!

Edit 2: Here’s a working example I created that does what I set out to accomplish. Hopefully this will be useful to others! animage1 is a 1000x1000px image… the point is it’s larger than the screen you’re using. animage2 is relatively small (100x100px). “Menu” is overloaded to toggle the visibility of that second image as a proof of concept.

package com.myname.testoverlay2;

//import android.widget.HorizontalScrollView; // Works with this as well

import com.myname.testoverlay2.TwoDScrollView;
// From - http://blog.gorges.us/2010/06/android-two-dimensional-scrollview/
//     with fix added from comments there

import android.app.Activity;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.os.Bundle;
import android.os.Handler;
import android.util.Log;
import android.view.Gravity;
import android.view.KeyEvent;
import android.view.ViewGroup.LayoutParams;
import android.widget.FrameLayout;
import android.widget.ImageView;

public class Testoverlay2Activity extends Activity {
    private static final String TAG = "MyApp";

    ImageView iv2;

    /** Called when the activity is first created. */
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);

        FrameLayout fl1 = new FrameLayout(this);
        FrameLayout.LayoutParams flp1 = new FrameLayout.LayoutParams(LayoutParams.FILL_PARENT, LayoutParams.FILL_PARENT);
        fl1.setId(9001);
        fl1.setLayoutParams(flp1);

        TwoDScrollView sv1 = new TwoDScrollView(this);
        sv1.setId(9002);

        FrameLayout fl2 = new FrameLayout(this);
        FrameLayout.LayoutParams flp2 = new FrameLayout.LayoutParams(LayoutParams.FILL_PARENT, LayoutParams.FILL_PARENT);
        fl2.setId(9003);
        fl2.setLayoutParams(flp2);

        ImageView iv1 = new ImageView(this);
        FrameLayout.LayoutParams ivp1 = new FrameLayout.LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT);
        iv1.setId(9004);
        iv1.setLayoutParams(ivp1);
        Bitmap bm1 = BitmapFactory.decodeResource(getResources(),
            getResources().getIdentifier("animage1" , "drawable", getPackageName()));
        iv1.setImageBitmap(bm1);
        //Log.d(TAG, "Bitmap1 = (" + bm1.getWidth() + ", " + bm1.getHeight() + ")");

        iv2 = new ImageView(this);
        FrameLayout.LayoutParams ivp2 = new FrameLayout.LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT, Gravity.CENTER);
        iv2.setId(9005);
        iv2.setLayoutParams(ivp2);
        Bitmap bm2 = BitmapFactory.decodeResource(getResources(),
            getResources().getIdentifier("animage2" , "drawable", getPackageName()));
        iv2.setImageBitmap(bm2);
        //Log.d(TAG, "Bitmap2 = (" + bm2.getWidth() + ", " + bm2.getHeight() + ")");

        // Lay everything out
        fl1.addView(sv1);
        fl1.addView(iv2);
        sv1.addView(fl2);
        fl2.addView(iv1);
        setContentView(fl1);

        // The following is based on a StackOverflow comment that scrollTo won't work immediately, in general...
        // http://stackoverflow.com/questions/4720469/horizontalscrollview-auto-scroll-to-end-when-new-views-are-added
        Handler mHandler = new Handler();
        mHandler.postDelayed(new Runnable() {
            public void run() {
                TwoDScrollView container=(TwoDScrollView)findViewById(9002);
                if (container != null) {
                    Log.d(TAG, "executing scrollTo()");
                    //container.setOverScrollMode(TwoDScrollView.OVER_SCROLL_IF_CONTENT_SCROLLS); // Needed?
                    container.scrollTo(500,500);
                }
                else {
                    Log.d("MyApp", "Container is null");
                }
            }
        }, 100L);  
    }

    // Keyboard wedge for testing convenience
    @Override
    public boolean onKeyDown(int keyCode, KeyEvent event) {
        Log.d(TAG, "Keypress = (" + keyCode + ")");
        switch (keyCode) {
        case KeyEvent.KEYCODE_MENU:
            /* Sample for handling the Menu button globally */
            if (iv2.getVisibility() == ImageView.VISIBLE) {
                iv2.setVisibility(ImageView.INVISIBLE);             
            }
            else {
                iv2.setVisibility(ImageView.VISIBLE);
            }
            return true;
        }
        return super.onKeyDown(keyCode, event);
    } 
}
  • 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-05-25T18:05:18+00:00Added an answer on May 25, 2026 at 6:05 pm

    You can extend the view class and override the ondraw method. Using the canvas, you can draw a bitmap and also text on top of it.

    From what i understood you need to have text appear in the middle and independent of the scrollview. This is the structure of the UI I would make

    <FrameLayout>
        <ScrollView>
            <Imageview/>
        </ScrollView>
        <TextView/>
    </FrameLayout>
    

    To create this layout programatically, this is roughly how you do it.

        ViewGroup.LayoutParams lp = new LayoutParams(LayoutParams.FILL_PARENT, 
                LayoutParams.FILL_PARENT);
    
        ScrollView sv = new ScrollView(this);
        sv.setLayoutParams(lp);
    
        TextView tx = new TextView(this);
        tx.setLayoutParams(lp);
        tx.setGravity(Gravity.CENTER);
        tx.setText("Test");
    
        FrameLayout fr = new FrameLayout(this);        
        fr.setLayoutParams(lp);
        fr.addView(sv);
        fr.addView(tx);
        setContentView(fr);
    

    The above code should go in the onCreate method. This is just how you do it roughly. You will need to make some modifications or additions to make it work for you.

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

Sidebar

Related Questions

I have a image here http://power.itp.ac.cn/~jmyang/funny/fun4.jpg and I want to display it in my
I have a 16 bit grayscale image that I want to display using WPF
I have this div: <div class=inauguration-image> I do not want this text to display,
I have an application that writes its own stylesheet, based off user input. It
I have an Image that is 1500x2048 I want this to display at its
I have a Drupal site that needs to display a unique header image based
I have overridden the windows ListBox in order to display an image and a
Scenario: You have an ASP.Net webpage that should display the next image in a
I have an object of type IMAGE which holds image. I wanted to display
How can i compress and image file(*bmp,*jpeg) in C#, I have to display some

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.