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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T19:37:36+00:00 2026-06-04T19:37:36+00:00

I have a custom layout with a nested view V like so: LinearLayout L1

  • 0

I have a custom layout with a nested view V like so:
LinearLayout L1 —> LinearLayout L2 —> View V.

I have an OnTouchListener registered for V. On a touch event, I need to get the coordinates of the touch event relative to the edges of view V.

What are the values returned by event.getX() and event.getY() relative to? I’ve googled around and am seeing conflicting statements, some say these values are already relative to view V’s edges, yet others say I need to subtract edge coordinates of view V from event.getX() and event.getY() to get relative coordinates.

Thanks for your help.

  • 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-04T19:37:37+00:00Added an answer on June 4, 2026 at 7:37 pm

    From Google’s documentation

    getX() method:

    The visual x position of this view, in pixels. This is equivalent to
    the translationX property plus the current left property.

    setTranslationX() method:

    Sets the horizontal location of this view relative to its left
    position. This effectively positions the object post-layout, in
    addition to wherever the object’s layout placed it.

    getLeft() method:

    Left position of this view relative to its parent.

    Therefore, getX() returns the view’s horizontal position relative to its parent.

    UPDATE:

    For event.getX() the result you get is also relative to the parent.
    You can do a simple test by placing a button inside a RelativeLayout which is horizontally centered and check the value when you click the button

    In your layout xml:

    <RelativeLayout
        android:layout_width="wrap_content"
        android:layout_height="wrap_content" android:layout_centerHorizontal="true">
    
        <Button
            android:id="@+id/button1"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="Button" />
    
    </RelativeLayout>
    

    In your activity:

        mBtn = ((Button) findViewById( R.id.button1 ));
        mBtn.setOnTouchListener( new OnTouchListener() {
    
            @Override
            public boolean onTouch(View v, MotionEvent event) {
                Log.d("", "getX = " + event.getX());
                return false;
            }
        });
    

    If you click the button on its left margin you will get a value close to 0.0.

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

Sidebar

Related Questions

I have a custom Layout shown below and I would like to update the
I have implemented a custom view within another activity into a XML layout. The
I have created a custom tab layout which look like this,I want to make
I have a list view with a custom layout. In the layout I display
I created a ListView with a custom layout for each view. I have several
I have this custom layout: - LinearLayout - FrameLayout - ImageView - TextView This
I have a custom spinner layout with an image and a text view but
I have a ListView that uses a custom layout that has 5 child View
I have custom component that I can place in my layout file (XML) for
I have custom gallery. Gallery represents items that are frame layout. There are one

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.