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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T06:25:02+00:00 2026-06-15T06:25:02+00:00

I want to create a toast that is anchored to a View (i.e., appears

  • 0

I want to create a toast that is anchored to a View (i.e., appears next a to given View).

I’ve tried

toast.setGravity(0, (int)v.getX(), (int)v.getY());

but this creates it in an entire location entirely.

If it matters, my view is an element in a TableRow.

Thanks

EDIT: I can’t use PopupWindow for this task.

  • 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-15T06:25:03+00:00Added an answer on June 15, 2026 at 6:25 am

    I think this Tutorial will help you to achieve what you want:

    public void onClick(View v) {
       int xOffset = 0;
       int yOffset = 0;
       Rect gvr = new Rect();
    
      View parent = (View) v.getParent();// v is the image,
        //parent is the rectangle holding it.
    
      if (parent.getGlobalVisibleRect(gvr)) {
            Log.v("image left", Integer.toString(gvr.left));
        Log.v("image right", Integer.toString(gvr.right));
        Log.v("image top", Integer.toString(gvr.top));
        Log.v("image bottom", Integer.toString(gvr.bottom));
        View root = v.getRootView();
    
            int halfwayWidth = root.getRight() / 2;
            int halfwayHeight = root.getBottom() / 2;
              //get the horizontal center
        int parentCenterX = ((gvr.right - gvr.left) / 2) + gvr.left;
         //get the vertical center
        int parentCenterY = (gvr.bottom - gvr.top) / 2 + gvr.top;
    
        if (parentCenterY <= halfwayHeight) {
           yOffset = -(halfwayHeight - parentCenterY);//this image is    above the center of gravity, i.e. the halfwayHeight
            } else {
            yOffset = parentCenterY - halfwayHeight;
            }
        if (parentCenterX < halfwayWidth) { //this view is left of center             xOffset = -(halfwayWidth - parentCenterX);    }   if (parentCenterX >= halfwayWidth) {
           //this view is right of center
           xOffset = parentCenterX - halfwayWidth;
        }
         }
           Toast toast = Toast.makeText(activity, altText, Toast.LENGTH_SHORT);
           toast.setGravity(Gravity.CENTER, xOffset, yOffset);
           toast.show();
           }
    });
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I used this link http://blog.androgames.net/85/android-accelerometer-tutorial/ to create an accelerometer. But I want that this
I want create wordpress website into which I want create user management... That means
i want create a custom json data from the mssql 2008 results so that
I want to create a new field (or two) in my table that is
I have a popup I want to create that will have 3 choices. (Block,
So, i want to create an app that can give it's user a notif
I want to create a message with Toast inside a SurfaceView class. With this
I want to create calendar. It is working. But if Android version +4.0. it
I want to create a app that shows data from a local db in
I need to create a similar function to Toast.makeText(...) but more fast to disappear.

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.