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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T23:43:03+00:00 2026-06-17T23:43:03+00:00

I have created my own component which extends RelativeLayout , inside it I have

  • 0

I have created my own component which extends RelativeLayout, inside it I have a field of View type which is being positioned with margins:

enter image description here

Blue quad represents my parent view, and a red circle is a child.

Now I want to allow user to move this red circle while moving a finger on a screen.
This is my onTouchEvent() method:

@Override
public boolean onTouchEvent(MotionEvent event) {

    int eventAction = event.getAction();

    switch (eventAction) {
        case MotionEvent.ACTION_DOWN: 
            // finger touches the screen
            break;

        case MotionEvent.ACTION_MOVE:
                marginX = (int)event.getX();
                marginY = (int)event.getY();
                RelativeLayout.LayoutParams lp = (RelativeLayout.LayoutParams)pointer.getLayoutParams(); // pointer is this red circle
                lp.setMargins(marginX, marginY, 0, 0);

            break;

        case MotionEvent.ACTION_UP:   
            // finger leaves the screen
            break;
    }


    return true;
}

But I quickly found out that it doesn’t refresh it’s position while user is moving his finger on a screen, but instead it does it only when user releases his finger from the screen. So basically, when I move my finger, circle stays in a same position, but when I stop moving, circle is drawn in new position. I tried using invalidate() method on both, parent and child views, but it didn’t help. I assume that it may have something to do with UI thread, but I don’t have access to runOnUiThread()' method as it's not anActivity`.

EDIT:
I passed an activity to my class, so that I can use runOnUiThread(). My case: ACTION_MOVE now looks like this:

case MotionEvent.ACTION_MOVE:      
    marginX = (int)event.getX();
    marginY = (int)event.getY();

    activity.runOnUiThread(new Runnable() {
        public void run() { 
        RelativeLayout.LayoutParams lp = (RelativeLayout.LayoutParams)pointer.getLayoutParams();
        lp.setMargins(marginX, marginY, 0, 0);
        pointer.invalidate();
        }
    });

break;
  • 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-17T23:43:04+00:00Added an answer on June 17, 2026 at 11:43 pm

    If it’s simple pointer you can draw it on Canvas as Drawable:

    @Override
    protected void onDraw(Canvas canvas) {
        pointer.setBounds(marginX, marginY, marginX + pointerWidth, marginY + pointerHeight);
        pointer.draw(canvas);
    
        super.onDraw(canvas);
    }
    

    And then call invalidate() on pointer in onTouchEvent() method.

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

Sidebar

Related Questions

I have created a custom list view, each row has it's own custom selector,
I have created my own component. When I add a new record to my
i have a big Joomla 1.5 Problem. I'll create my own Gallery Component/PlugIn and
I have created my own Attached Property like this: public static class LabelExtension {
I have created my own customized lots of architecture including n-tier layers for different
I have created my own debugger application. It attaches to a process and creates
I have created my own button class called custom_btn. I created it on the
I have created blank Asp.Net-MVC 3 web application and want to write my own
I have my own asp.net cookie created like this: var authTicket = new FormsAuthenticationTicket(
I have a website already running made with CakePHP, which has its own login

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.