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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 3, 20262026-06-03T06:51:17+00:00 2026-06-03T06:51:17+00:00

So I’ve searched high and low but couldn’t find an answer to my question.

  • 0

So I’ve searched high and low but couldn’t find an answer to my question. What I basically need is the behavior provided by Android’s ViewFlipper or ViewPager but I want to display portions of the left and right views, to indicate the user there are elements to scroll, instead of having the selected view occupying the whole screen.

I would also like to add some effects to the left and side views, like dimming and scaling then down a little. Is it possible to do it with the stock ViewFlipper or ViewPager or do I have to roll out my own view group, à la cover flow (http://www.inter-fuser.com/2010/01/android-coverflow-widget.html)?

(P.S. I don’t want to use the Gallery widget, that component sucks).

This is what we need to display once a view is selected (left and right views are still displayed):

view switcher

Flinging left or right would transition the main view out, dimming and reducing it a little and doing the opposite with the next or previous view.

  • 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-03T06:51:18+00:00Added an answer on June 3, 2026 at 6:51 am

    I would like to give an update to anyone who might want the same feature. A lot of progress has been made to implement this feature so far and now the view is working exactly as we need it to.

    The ViewPager has a method called setPageMargin(). This method can receive a negative value which will make the fragments/views to overlap each other. To arrive at the desired layout, we first dynamically calculated the left and right margins by a percentage of the screen. This can be done statically as well but since we will be targeting a range of different screen sizes, this seems to be the best approach.

    Later we set the ViewPager’s page margin to 2 times the size of the side margins. This makes the views snap back together. However, at this time, there will be more than one view being displayed by the ViewPager.

    All you have left to do is to either apply a transform (scale) to the views to the left and right (Android 3.0+) or add some more margins around them to shrink them to the right size (pre 3.0).

    The OnPageChangeListener.onPageScrolled() can be used to track the ViewPager’s scrolling. A smooth
    transformation can be achieved. The code looks like this:

    private OnPageChangeListener onPageChangeListener = new OnPageChangeListener() {
    
        @Override
        public void onPageSelected(int position) {
        }
    
        @Override
        public void onPageScrolled(int position, float positionOffset, int positionOffsetPixels) {
    
            // positionOffset varies from 0 to 1 and indicates how far the view is
            // from the center of the ViewPager. When a view is selected (centered), this
            // value is 0.
    
            // Fades the text in an out while the ViewPager scrolls from one view to another.
            // On our final design the text views are fixed to the center of the screen and
            // do not scroll along with the views.
            if (positionOffset < 0.5) {
                setTextViewAlpha(1 - positionOffset * 2);
            } else {
                setTextViewAlpha((positionOffset - 0.5f) * 2);
            }
    
            // It's surprisingly complicated to get the current object being displayed by
            // a ViewPager (there's no getCurrentObject method). ScaleableFragment is just
            // a custom class to allow an adapter to cache it internally and also correctly
            // manage a fragment's lifecycle and restore from a saved state.
            ScaleableFragment sampleFragment = (ScaleableFragment) ((ShowHeroShotImageFragmentPagerAdapter) pager
                    .getAdapter()).getItem(position);
    
            // Calculates by how much the current view will be scaled down. The RATIO_SCALE
            // is 0.3 in our case, which makes the side views 70% of the size of the
            // center view. When centered, the scale will be 1. When
            // fully scrolled, the scale will be 0.7.
            float scale = 1 - (positionOffset * RATIO_SCALE);
    
            // Just a shortcut to findViewById(R.id.image).setScale(scale);
            sampleFragment.scaleImage(scale);
    
    
            // Now, if not in the last element, scale the next one up (in opposite direction).
            if (position + 1 < pager.getAdapter().getCount()) {
                sampleFragment = (ScaleableFragment) ((ShowHeroShotImageFragmentPagerAdapter) pager.getAdapter())
                        .getItem(position + 1);
                scale = positionOffset * RATIO_SCALE + (1 - RATIO_SCALE);
                sampleFragment.scaleImage(scale);
            }
        }
    
        // Once scrolling is done. Make sure the views are in the right scale (1 for center,
        // 0.7 for sides). Required as the onPageScrolled() method does not guarantee it
        // will interpolate to 1.0 precisely.
        @Override
        public void onPageScrollStateChanged(int state) {
            if (state == ViewPager.SCROLL_STATE_IDLE) {
                setTextViewAlpha(1);
                ScaleableFragment sampleFragment = (ScaleableFragment) ((ShowHeroShotImageFragmentPagerAdapter) pager
                        .getAdapter()).getItem(pager.getCurrentItem());
                sampleFragment.scaleImage(1);
                sampleFragment.enableClicks();
    
                if (pager.getCurrentItem() > 0) {
                    sampleFragment = (ScaleableFragment) ((ShowHeroShotImageFragmentPagerAdapter) pager.getAdapter())
                            .getItem(pager.getCurrentItem() - 1);
                    sampleFragment.scaleImage(1 - RATIO_SCALE);
                    sampleFragment.disableClicks();
                }
    
                if (pager.getCurrentItem() + 1 < pager.getAdapter().getCount()) {
                    sampleFragment = (ScaleableFragment) ((ShowHeroShotImageFragmentPagerAdapter) pager.getAdapter())
                            .getItem(pager.getCurrentItem() + 1);
                    sampleFragment.scaleImage(1 - RATIO_SCALE);
                    sampleFragment.disableClicks();
                }
            }
        }
    };
    

    This is it. I didn’t post the full solution but I hope this is enough to get someone else started.

    P.S. On 3.0+ enable hardware acceleration. Without it, the scrolling looked choppy on a samsung galaxy tab 10.1.

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

Sidebar

Related Questions

I need to clean up various Word 'smart' characters in user input, including but
Seemingly simple, but I cannot find anything relevant on the web. What is the
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I want to count how many characters a certain string has in PHP, but
Basically, what I'm trying to create is a page of div tags, each has
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I have a French site that I want to parse, but am running into
In my XML file chapters tag has more chapter tag.i need to display chapters
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
I need a function that will clean a strings' special characters. I do NOT

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.