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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T07:43:26+00:00 2026-06-12T07:43:26+00:00

I did a coding for ribbon menu using horizontal scrollview. my code is given

  • 0

I did a coding for ribbon menu using horizontal scrollview. my code is given below:

public class HorzScrollWithListMenuActivity extends Activity {


        MyHorizontalScrollView scrollView;
        View menu;
        View app;
        ImageView btnSlide;
        boolean menuOut = false;
        Handler handler = new Handler();
        int btnWidth;

        @Override
        public void onCreate(Bundle savedInstanceState) {
            super.onCreate(savedInstanceState); 

            LayoutInflater inflater = LayoutInflater.from(HorzScrollWithListMenuActivity.this);
            scrollView = (MyHorizontalScrollView) inflater.inflate(R.layout.horz_scroll_with_list_menu, null);
            setContentView(scrollView); 

            menu = inflater.inflate(R.layout.horz_scroll_menu, null);
            app = inflater.inflate(R.layout.horz_scroll_app, null);
            ViewGroup tabBar = (ViewGroup) app.findViewById(R.id.tabBar);

            ListView listView = (ListView) app.findViewById(R.id.list);
            ViewUtils.initListView(this, listView, "Item ", 50, android.R.layout.simple_list_item_1);

            listView = (ListView) menu.findViewById(R.id.list);
            ViewUtils.initListView(this, listView, "Menu ", 30, android.R.layout.simple_list_item_1);

            btnSlide = (ImageView) tabBar.findViewById(R.id.BtnSlide);
            btnSlide.setOnClickListener(new ClickListenerForScrolling(scrollView, menu,app));

            final View[] children = new View[] { menu, app };

            // Scroll to app (view[1]) when layout finished.
            int scrollToViewIdx = 1;
            scrollView.initViews(children, scrollToViewIdx, new SizeCallbackForMenu(btnSlide));
        }

        /**
         * Helper for examples with a HSV that should be scrolled by a menu View's width.
         */
        static class ClickListenerForScrolling implements OnClickListener {
            HorizontalScrollView scrollView;
            View menu;
            View app;
            /**
             * Menu must NOT be out/shown to start with.
             */
            boolean menuOut = false;

            public ClickListenerForScrolling(HorizontalScrollView scrollView, View menu, View app) {
                super();
                this.scrollView = scrollView;
                this.menu = menu;
                this.app=app;
            }

            public void onClick(View v) {
                Context context = menu.getContext();
                String msg = "Slide " + new Date();
                Toast.makeText(context, msg, 1000).show();
                System.out.println(msg);


                int menuWidth = menu.getMeasuredWidth();

                // Ensure menu is visible
                menu.setVisibility(View.VISIBLE);

                if (!menuOut) {
                    // Scroll to 0 to reveal menu
                    int left = 0;
                    scrollView.smoothScrollTo(left, 0);

                } else {
                    // Scroll to menuWidth so menu isn't on screen.
                    int left = menuWidth;
                    scrollView.smoothScrollTo(left, 0);

                }
                menuOut = !menuOut;
                if(v.isPressed())
                {
                    v.setClickable(false);

                }


            }
        }

        /**
         * Helper that remembers the width of the 'slide' button, so that the 'slide' button remains in view, even when the menu is
         * showing.
         */
        static class SizeCallbackForMenu implements SizeCallback {
            int btnWidth;
            View btnSlide;

            public SizeCallbackForMenu(View btnSlide) {
                super();
                this.btnSlide = btnSlide;
            }

            public void onGlobalLayout() {
                btnWidth = btnSlide.getMeasuredWidth();
                System.out.println("btnWidth=" + btnWidth);
            }

            public void getViewSize(int idx, int w, int h, int[] dims) {
                dims[0] = w;
                dims[1] = h;
                final int menuIdx = 0;
                if (idx == menuIdx) {
                    dims[0] = w - btnWidth;
                }
            }
        }
    }

MyHorizontalScrollView.java

public class MyHorizontalScrollView extends HorizontalScrollView {
    public MyHorizontalScrollView(Context context, AttributeSet attrs, int defStyle) {
        super(context, attrs, defStyle);
        init(context);
    }

    public MyHorizontalScrollView(Context context, AttributeSet attrs) {
        super(context, attrs);
        init(context);
    }

    public MyHorizontalScrollView(Context context) {
        super(context);
        init(context);
    }

    void init(Context context) {
        // remove the fading as the HSV looks better without it
        setHorizontalFadingEdgeEnabled(false);
        setVerticalFadingEdgeEnabled(false);
    }

    /**
     * @param children
     *            The child Views to add to parent.
     * @param scrollToViewIdx
     *            The index of the View to scroll to after initialisation.
     * @param sizeCallback
     *            A SizeCallback to interact with the HSV.
     */
    public void initViews(View[] children, int scrollToViewIdx, SizeCallback sizeCallback) {
        // A ViewGroup MUST be the only child of the HSV
        ViewGroup parent = (ViewGroup) getChildAt(0);

        // Add all the children, but add them invisible so that the layouts are calculated, but you can't see the Views
        for (int i = 0; i < children.length; i++) {
            children[i].setVisibility(View.INVISIBLE);
            parent.addView(children[i]);
        }

        // Add a layout listener to this HSV
        // This listener is responsible for arranging the child views.
        OnGlobalLayoutListener listener = new MyOnGlobalLayoutListener(parent, children, scrollToViewIdx, sizeCallback);
        getViewTreeObserver().addOnGlobalLayoutListener(listener);
    }

    @Override
    public boolean onTouchEvent(MotionEvent ev) {
        // Do not allow touch events.
        return false;
    }

    @Override
    public boolean onInterceptTouchEvent(MotionEvent ev) {
        // Do not allow touch events.
        return false;
    }

    /**
     * An OnGlobalLayoutListener impl that passes on the call to onGlobalLayout to a SizeCallback, before removing all the Views
     * in the HSV and adding them again with calculated widths and heights.
     */
    class MyOnGlobalLayoutListener implements OnGlobalLayoutListener {
        ViewGroup parent;
        View[] children;
        int scrollToViewIdx;
        int scrollToViewPos = 0;
        SizeCallback sizeCallback;

        /**
         * @param parent
         *            The parent to which the child Views should be added.
         * @param children
         *            The child Views to add to parent.
         * @param scrollToViewIdx
         *            The index of the View to scroll to after initialisation.
         * @param sizeCallback
         *            A SizeCallback to interact with the HSV.
         */
        public MyOnGlobalLayoutListener(ViewGroup parent, View[] children, int scrollToViewIdx, SizeCallback sizeCallback) {
            this.parent = parent;
            this.children = children;
            this.scrollToViewIdx = scrollToViewIdx;
            this.sizeCallback = sizeCallback;
        }

        public void onGlobalLayout() {
            // System.out.println("onGlobalLayout");

            final HorizontalScrollView me = MyHorizontalScrollView.this;

            // The listener will remove itself as a layout listener to the HSV
            me.getViewTreeObserver().removeGlobalOnLayoutListener(this);

            // Allow the SizeCallback to 'see' the Views before we remove them and re-add them.
            // This lets the SizeCallback prepare View sizes, ahead of calls to SizeCallback.getViewSize().
            sizeCallback.onGlobalLayout();

            parent.removeViewsInLayout(0, children.length);

            final int w = me.getMeasuredWidth();
            final int h = me.getMeasuredHeight();

            // System.out.println("w=" + w + ", h=" + h);

            // Add each view in turn, and apply the width and height returned by the SizeCallback.
            int[] dims = new int[2];
            scrollToViewPos = 0;
            for (int i = 0; i < children.length; i++) {
                sizeCallback.getViewSize(i, w, h, dims);
                // System.out.println("addView w=" + dims[0] + ", h=" + dims[1]);
                children[i].setVisibility(View.VISIBLE);

                parent.addView(children[i], dims[0], dims[1]);
                if (i < scrollToViewIdx) {
                    scrollToViewPos += dims[0];
                }
            }

            // For some reason we need to post this action, rather than call immediately.
            // If we try immediately, it will not scroll.
            new Handler().post(new Runnable() {
                public void run() {
                    me.scrollBy(scrollToViewPos, 0);
                }
            });
        }
    }

    /**
     * Callback interface to interact with the HSV.
     */
    public interface SizeCallback {
        /**
         * Used to allow clients to measure Views before re-adding them.
         */
        public void onGlobalLayout();

        /**
         * Used by clients to specify the View dimensions.
         * 
         * @param idx
         *            Index of the View.
         * @param w
         *            Width of the parent View.
         * @param h
         *            Height of the parent View.
         * @param dims
         *            dims[0] should be set to View width. dims[1] should be set to View height.
         */
        public void getViewSize(int idx, int w, int h, int[] dims);
    }
}

ViewUtils.java

public class ViewUtils {
    private ViewUtils() {
    }


    public static void initListView(Context context, ListView listView, String prefix, int numItems, int layout) {
        // By using setAdpater method in listview we an add string array in list.
        String[] arr = new String[numItems];
        for (int i = 0; i < arr.length; i++) {
            arr[i] = prefix + (i + 1);
        }
        listView.setAdapter(new ArrayAdapter<String>(context, layout, arr));
        listView.setOnItemClickListener(new OnItemClickListener() {
            public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
                Context context = view.getContext();
                String msg = "item[" + position + "]=" + parent.getItemAtPosition(position);
                Toast.makeText(context, msg, 1000).show();
                System.out.println(msg);
            }
        });
    }
}

Please tell me how to give swipe option.

How to do the same project(Ribbon menu) using fragments?

  • 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-12T07:43:27+00:00Added an answer on June 12, 2026 at 7:43 am

    ActionBarSherlock is very useful library to build that kinds of apps,

    Please check first this library,
    http://actionbarsherlock.com/

    Then checkout this project,
    https://bitbucket.org/owentech/abstabsviewpager/

    I hope it will help to solve your problem.

    Happy coding…

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

Sidebar

Related Questions

Consider the following code (for simplicity, I did not follow any C# coding rules).
I have did coding as in ViewDidLoad as below // Implement viewDidLoad to do
My problem is, I did coding for a sprite. It should change it should
I never did any serious Java coding before, but I learned the syntax, libraries,
The last time I did any serious Java coding was back around the turn
Did I not get enough sleep or what? This following code var frame=document.getElementById(viewer); frame.width=100;
It's been about 6 months since I did any coding. The life of a
I'm coding my first more serious web design using div's and CSS styling (I'm
We are in the beginning coding phase for project that we are using JPA
I did an app that sets the wallpaper using several png images on timed

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.