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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T15:23:19+00:00 2026-06-15T15:23:19+00:00

I want to move a view on touch and when the user unholds this

  • 0

I want to move a view on touch and when the user unholds this view, it is started an animation which moves my view to the end of its parent.

This is my layout:

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:id="@+id/time_view"
    android:layout_width="match_parent"
    android:layout_height="match_parent" >

<AbsoluteLayout
    android:id="@+id/slide_layout"
    android:layout_width="match_parent"
    android:layout_height="50dp"
    android:layout_alignParentBottom="true"
    android:layout_margin="20dp"
    android:background="#0000FF" >

    <View
        android:id="@+id/slide_to_pause"
        android:layout_width="50dp"
        android:layout_height="50dp"
        android:background="#00FFFF" />
</AbsoluteLayout>
</RelativeLayout>

This is how I set the view to move in my onCreate:

slideView = ((View) findViewById(R.id.slide_to_pause));
slideView.setOnTouchListener(this);

This is how I move the view and starts the animation:

@Override
public boolean onTouch(View view, MotionEvent event) {
    AbsoluteLayout.LayoutParams layoutParams = (AbsoluteLayout.LayoutParams) view.getLayoutParams();

    switch (event.getAction() & MotionEvent.ACTION_MASK) {

    case MotionEvent.ACTION_DOWN:
        mX = event.getRawX();
        break;

    case MotionEvent.ACTION_UP:
        int endOfAnimation = findViewById(R.id.slide_layout).getWidth() - view.getWidth();
        mSlideAnimation = new TranslateAnimation(0, endOfAnimation - layoutParams.x, 0, 0);
        mSlideAnimation.setDuration(1000);          
        view.startAnimation(mSlideAnimation);
        Log.d(TAG, "endOfAnimation = " + layoutParams.x + " | " + endOfAnimation);
        break;

    case MotionEvent.ACTION_MOVE:
        layoutParams.x = (int) event.getRawX();         
        view.setLayoutParams(layoutParams); 

        break;
    }
    return true;
}

The problem is that when the view arrives at the end it comes back to a point in the midle of the screen, which is the point where the user unholds the view.
How can I fix this?
Thank you!

  • 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-15T15:23:20+00:00Added an answer on June 15, 2026 at 3:23 pm

    You need to use

    mSlideAnimation.setFillAfter(true);
    

    to make it not revert back to the start.

    If that doesn’t work you might have to follow the suggestion on Animation.setFillAfter/Before – Do they work/What are they for?

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

Sidebar

Related Questions

I have a view with button and touch-move gesture. When user touches button it
i have one code which moves the uiimage on touch-event it's like this: -(void)touchesBegan:(NSSet
I want to have a game where the view will move around as the
I want to move an image within a circle with my touch on move.
I have an image in a view which contains a 9x9 grid. I want
I want to move my body continuos when i touch screen and stop when
i have text View in layout and set text in layout..now i want to
i want to get pixel value when i touch my screen. its in a
I want to move to a new server and automate the process of moving
I want to move cells just as these two methods do: - (void)tableView:(UITableView *)tableView

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.