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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T09:37:35+00:00 2026-06-14T09:37:35+00:00

I am trying to show horizontal scroll view with images to scroll in two

  • 0

I am trying to show horizontal scroll view with images to scroll in two directions.Previously for this i used Gallery View but galleryview is deprected ,i am using horizontal scroll view instead of gallery view but horizontal scroll view is different with gallery view.

Now i have to do two implementation

1) Scrolling in two directions continuously.

2) Center lock feature as same as gallery.

My screen looks like

enter image description here

  • 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-14T09:37:36+00:00Added an answer on June 14, 2026 at 9:37 am

    you can use viewpager,

    try this code and modify it as your need .

    note : this not my code already found it on the net belong to:

    ( Dave Smith,@devunwired Date: 8/17/12 PagerActivity).

    MainActivity:

      public class MainActivity extends Activity{
    
    
    PagerContainer  mContainer;
    
    public void onCreate(Bundle savedInstanceState)
    {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
    
        mContainer = (PagerContainer) findViewById(R.id.pager_container);
    
        ViewPager pager = mContainer.getViewPager();
        PagerAdapter adapter = new MyPagerAdapter();
        pager.setAdapter(adapter);
        // Necessary or the pager will only have one extra page to show
        // make this at least however many pages you can see
        pager.setOffscreenPageLimit(adapter.getCount());
        // A little space between pages
        pager.setPageMargin(15);}
    
    // Nothing special about this adapter, just throwing up colored views for
    // demo
    private class MyPagerAdapter extends PagerAdapter{
    
        @Override
        public Object instantiateItem(ViewGroup container, int position){
            TextView view = new TextView(MainActivity.this);
            view.setText("Item " + position);
            view.setGravity(Gravity.CENTER);
            view.setBackgroundColor(Color.argb(255, position * 50,
                    position * 10, position * 50));
    
            container.addView(view);
            return view;
                                     }
    
        @Override
        public void destroyItem(ViewGroup container, int position, Object object)
                    {
            container.removeView((View) object);}
    
    
        @Override
        public int getCount(){
         return 5;
                 }
    
        @Override
        public boolean isViewFromObject(View view, Object object)
             {
            return (view == object);
                   }}}
    

    PagerContainer:

      public class PagerContainer extends FrameLayout implements
                ViewPager.OnPageChangeListener {
    
      private ViewPager mPager;
      boolean mNeedsRedraw = false;
    
      public PagerContainer(Context context) {
        super(context);
        init();
                          }
    
    public PagerContainer(Context context, AttributeSet attrs) {
        super(context, attrs);
        init();
            }
    
    public PagerContainer(Context context, AttributeSet attrs, int defStyle) {
        super(context, attrs, defStyle);
        init();
                     }
    
    private void init() {
        setClipChildren(false);
                       }
    
    @Override
    protected void onFinishInflate() {
        try {
            mPager = (ViewPager) getChildAt(0);
            mPager.setOnPageChangeListener(this);
        } catch (Exception e) {
         throw new IllegalStateException("The root child of PagerContainer must be a
                      ViewPager");
                      }
                    }
    
    public ViewPager getViewPager() {
        return mPager;
                   }
    
    private Point mCenter = new Point();
    private Point mInitialTouch = new Point();
    
    @Override
    protected void onSizeChanged(int w, int h, int oldw, int oldh) {
        mCenter.x = w / 2;
        mCenter.y = h / 2;
                }
    
    @Override
    public boolean onTouchEvent(MotionEvent ev) {
        //We capture any touches not already handled by the ViewPager
        // to implement scrolling from a touch outside the pager bounds.
        switch (ev.getAction()) {
            case MotionEvent.ACTION_DOWN:
                mInitialTouch.x = (int)ev.getX();
                mInitialTouch.y = (int)ev.getY();
            default:
                ev.offsetLocation(mCenter.x - mInitialTouch.x, mCenter.y -
                   mInitialTouch.y);
                break;
                    }
    
        return mPager.dispatchTouchEvent(ev);
                      }
    
    public void onPageScrolled(int position, float positionOffset, int
               positionOffsetPixels) {
        //Force the container to redraw on scrolling.
        //Without this the outer pages render initially and then stay static
        if (mNeedsRedraw) invalidate();
                     }
    
    public void onPageSelected(int position) { }
    
    public void onPageScrollStateChanged(int state) {
        mNeedsRedraw = (state != ViewPager.SCROLL_STATE_IDLE);
               }
                }
    

    activity_main.xml:

     <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
             android:layout_width="match_parent"
             android:layout_height="match_parent" >
    
    <com.example.testviewpager.PagerContainer
        android:id="@+id/pager_container"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:background="#CCC" >
    
        <android.support.v4.view.ViewPager
            android:layout_width="150dp"
            android:layout_height="100dp"
            android:layout_gravity="center_horizontal" />
    </com.example.testviewpager.PagerContainer>
    
     </RelativeLayout>
    

    hope help you.

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

Sidebar

Related Questions

I am trying to get text to show above some horizontal lines. But try
I am trying to write a photo gallery that show images with GridView. Images
I am trying to show correlation between two individual lists. Before installing Numpy, I
I'm trying to make a horizontal menu with CSS but i've run into a
I am trying to create my custom view through xml, but the screen does
I'm trying to make a simple app to show pictures. The images get scaled
I am trying to show a pair of hidden buttons (using setVisibility(View.VISIBLE) , within
I am trying to show some random images in a div. My HTML code
This is my first time trying to use a custom view in XML and
I'm trying to do a horizontal list using the style type below but when

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.