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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T14:39:45+00:00 2026-06-18T14:39:45+00:00

I want to move a view when the ViewPager scrolls. I found scroll listener

  • 0

I want to move a view when the ViewPager scrolls. I found scroll listener in view pager, with the parameter positionOffset, which I use to adjust the left margin of the view I want to move.

It works, but the scrolling isn’t smooth anymore. If I comment the scroll listener out, it’s smooth again. The view I’m animating is super simple – only a small square with a plain color. The requestLayout() call is done only on this view. The code:

pager.setOnPageChangeListener(new ViewPager.OnPageChangeListener() {
    @Override
    public void onPageSelected(int position) {
    }
    @Override
    public void onPageScrolled(int position, float positionOffset, int positionOffsetPixels) {
        if (positionOffset != 0 || (positionOffset == 0 && position == 0)) {
            pars.leftMargin = (int)(scrollablePart * positionOffset);
            tabBG.requestLayout();
        }

    }

    @Override
    public void onPageScrollStateChanged(int state) {
    }
});

I don’t know what’s the problem, I have other place with a view which I animate in a similar way (adjusting margins, according to a -not pager-slider) and it’s smooth. I also have seen an app where the positions of some views are adjusted dynamically according to the scrolling of a pager, and it’s very smooth.

Any idea? Thanks in advance!

  • 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-18T14:39:46+00:00Added an answer on June 18, 2026 at 2:39 pm

    Any animation that involves requestLayout() will be slow. If all you are trying to do is move a View around, use a TranslateAnimation, or View.offsetLeftAndRight() or View.setTranslationX(), etc. Do not use requestLayout() or anything layout related.

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

Sidebar

Related Questions

I want to have a game where the view will move around as the
I want an image view of some size say 25 by 25, to move
I have attached a UILabel to view. Now i want to move that label
Essentially, what I want to do is to move a view around to follow
I have a View which I want to be draggable so I've overridden its
I want to move the view when TextField is clicked but it works only
I want to move from one view controller to the next, using code. I
i am using edit text view and want to move to the next text
I have an image in a view which contains a 9x9 grid. I want
I want to move a view on touch and when the user unholds this

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.