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

  • Home
  • SEARCH
  • 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 8717521
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T06:19:29+00:00 2026-06-13T06:19:29+00:00

So I have an ImageView in my layout and I wanted to slide it

  • 0

So I have an ImageView in my layout and I wanted to slide it to the right or left when the user swipe over the latter. I used TranslateAnimation to translate the ImageView, as shown below.

ImageView logoFocus = (ImageView) findViewById(R.id.logoFocus);

Animation animSurprise2Movement = new TranslateAnimation(logoFocus.getLeft(), logoFocus.getLeft()+150, logoFocus.getTop(), logoFocus.getTop());
animSurprise2Movement.setDuration(1000);
animSurprise2Movement.setFillAfter(true);
animSurprise2Movement.setFillEnabled(true);
logoFocus.startAnimation(animSurprise2Movement);

I’ve placed this code in my Swipe Right section, and the same code but using getLeft()-150 for the Swipe Left section. It works as expected when I swipe a first time, but when I swipe to the other direction, the ImageView goes back to its original position, then slides in the other direction, instead of only sliding to the original position.

I’ve already tried to add the following in the onAnimationEnd method of an AnimationListener which I’ve set to the Animation, but in vain.

MarginLayoutParams params = (MarginLayoutParams) logoFocus.getLayoutParams();
params.setMargins(logoFocus.getLeft()+150, logoFocus.getTop(), logoFocus.getRight(), logoFocus.getBottom());
logoFocus.setLayoutParams(params);

I’ve also tried the following in the same method, but that neither didn’t work as expected.

((RelativeLayout.LayoutParams) logoFocus.getLayoutParams()).leftMargin += 150;
logoFocus.requestLayout();

Would anyone please help me? The position doesn’t seem to change after the Animation, even with setFillAfter(true) and setFillEnabled(true) used. Is there an alternative to using TranslateAnimation?

Thank you for any help I can get. 🙂

  • 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-13T06:19:30+00:00Added an answer on June 13, 2026 at 6:19 am

    Okay, so I worked my way around it. I’m using a global variable now which I update each time I animate the ImageView, instead of trying to force the ImageView to change its actual position. Since I’m using setFillAfter(true) and setFillEnabled(true), it doesn’t go back unintentionally to its original position anymore.

    private float xCurrentPos, yCurrentPos;
    private ImageView logoFocus;
    
    logoFocus = (ImageView) findViewById(R.id.logoFocus); 
    xCurrentPos = logoFocus.getLeft(); 
    yCurrentPos = logoFocus.getTop(); 
    
    Animation anim= new TranslateAnimation(xCurrentPos, xCurrentPos+150, yCurrentPos, yCurrentPos); 
    anim.setDuration(1000); 
    anim.setFillAfter(true); 
    anim.setFillEnabled(true); 
    animSurprise2Movement.setAnimationListener(new AnimationListener() {
    
        @Override
        public void onAnimationStart(Animation arg0) {}
    
        @Override
        public void onAnimationRepeat(Animation arg0) {}
    
        @Override
        public void onAnimationEnd(Animation arg0) {
            xCurrentPos -= 150;
        }
    });
    logoFocus.startAnimation(anim);
    

    Hope this helps if you’re having the same problem. I’ve seen several posts like this with no good answer.

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

Sidebar

Related Questions

My layout have ImageView(iv) and TextView(tv). I want to let the tv right of
Hi I have created a relative layout. and align the imageview to the right
I have this ImageView in my layout: <ImageView android:layout_width=fill_parent android:layout_height=wrap_content android:contentDescription=@string/image_divider android:paddingBottom=8dp android:paddingTop=4dp android:scaleType=fitXY
I have imageView inside a relative layout. And when i create the activity i
I have a ImageView in my relative layout. How can I get all the
I have an appwidget layout with a textview and an imageview. Lint always tells
I have a layout which looks like this: <LinearLayout> <ImageView> android:width=wrap_content android:height:wrap_content ... </ImageView>
I have <.ImageView> enter code here s(icons) in my android layout xml file, which
I have an ImageView for which I wanted to implement the onClickListener. But when
I have an ImageView in my android layout. And I would like to add

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.