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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 29, 20262026-05-29T06:36:17+00:00 2026-05-29T06:36:17+00:00

I am using Horizontal Scroll View, dynamically i will add items in to that.

  • 0

I am using Horizontal Scroll View, dynamically i will add items in to that. if no. of items are more than displaying items on the screen i want to show image(arrow) at the edges ( like scroll view shows fading edges). How can i do it.

just look at below image, i want create like that.

this is the xml code

<HorizontalScrollView 
   android:layout_width="wrap_content"
   android:scrollbars="none"
   android:id="@+id/app_category"
   android:layout_below="@+id/top_layout"   
   android:background="@drawable/minitopbar"
   android:layout_height="30dp">

   <LinearLayout 
     android:orientation="horizontal"
     android:id="@+id/app_category_scroll_layout"
     android:layout_width="wrap_content"                            
     android:layout_height="fill_parent"/>

</HorizontalScrollView>

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-05-29T06:36:18+00:00Added an answer on May 29, 2026 at 6:36 am

    A. You have to create your own class, that extends HorizontalScrollView:

    public class ExtendedHorizontalScrollView extends HorizontalScrollView {
    
    private IScrollStateListener scrollStateListener;
    
    public HorizontalScrollViewForMenu(Context context, AttributeSet attrs, int defStyle) {
        super(context, attrs, defStyle);
    }
    
    public HorizontalScrollViewForMenu(Context context, AttributeSet attrs) {
        super(context, attrs);
    }
    
    public HorizontalScrollViewForMenu(Context context) {
        super(context);
    }
    
    @Override
    protected void onLayout(boolean changed, int l, int t, int r, int b) {
        super.onLayout(changed, l, t, r, b);
        prepare();
    }
    
    private void prepare() {
        if (scrollStateListener != null) {
            View content = this.getChildAt(0);
            if (content.getLeft() >= 0)
                scrollStateListener.onScrollMostLeft();
            if (content.getLeft() < 0)
                scrollStateListener.onScrollFromMostLeft();
    
            if (content.getRight() <= getWidth())
                scrollStateListener.onScrollMostRight();
            if (content.getLeft() > getWidth())
                scrollStateListener.onScrollFromMostRight();
        }
    }
    
    @Override
    protected void onScrollChanged(int l, int t, int oldl, int oldt) {
        super.onScrollChanged(l, t, oldl, oldt);
        if (scrollStateListener != null) {
            if (l == 0)
                scrollStateListener.onScrollMostLeft();
            else if (oldl == 0)
                scrollStateListener.onScrollFromMostLeft();
            int mostRightL = this.getChildAt(0).getWidth() - getWidth();
            if (l >= mostRightL)
                scrollStateListener.onScrollMostRight();
            if (oldl >= mostRightL && l < mostRightL)
                scrollStateListener.onScrollFromMostRight();
        }
    }
    
    public void setScrollStateListener(IScrollStateListener listener) {
        scrollStateListener = listener;
    }
    
    public interface IScrollStateListener {
        void onScrollMostLeft();
    
        void onScrollFromMostLeft();
    
        void onScrollMostRight();
    
        void onScrollFromMostRight();
    }
    }
    

    B. Use it defining of layout:

    <LinearLayout
          .....>
        <ImageView
            android:id="@+id/navigation_left"
            ..... />
    
        <your.custom.view.package.ExtendedHorizontalScrollView
            android:id="@+id/scroller"
            android:layout_width="0px"
            android:layout_weight="1"
            android:fadingEdge="none"
                    ....>
            <LinearLayout
                android:orientation="horizontal"
                android:layout_width="match_parent"
                android:layout_height="match_parent" />
        </your.custom.view.package.ExtendedHorizontalScrollView>
    
        <ImageView
            android:id="@+id/navigation_right"
            ..... />
    
    </LinearLayout>
    

    C. Add logic for disabling arrows when you can’t scroll any more.

    ((ExtendedHorizontalScrollView)findViewById(R.id.scroller)).setScrollStateListener(new IScrollStateListener() {
            public void onScrollMostRight() {
                ((View) scroller.getParent()).findViewById(R.id.navigation_right).setVisibility(View.INVISIBLE);
            }
    
            public void onScrollMostLeft() {
                ((View) scroller.getParent()).findViewById(R.id.navigation_left).setVisibility(View.INVISIBLE);
            }
    
            public void onScrollFromMostLeft() {
                ((View) scroller.getParent()).findViewById(R.id.navigation_left).setVisibility(View.VISIBLE);
            }
    
            public void onScrollFromMostRight() {
                ((View) scroller.getParent()).findViewById(R.id.navigation_right).setVisibility(View.VISIBLE);
            }
    
        });
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm creating a dynamically generated PDF using FPDF. My PDF requires many exactly horizontal/vertical
I am using a layout with Scroll View. But in Logcat I got this
I want to display the images present in my database on the Scroll view.Also
I am using a scrollview to display various items in a horizontal fashion. How
I am using a HorizentalScrollView in a view. I add TextView at runtime. I
I have a horizontal scroll view, and inside I have a number of image
Having trouble with a horizontal scroll bar that pops up. My page is set
I am looking to implement horizontal scrolling using jQuery.SerialScroll (based on jQuery.ScrollTo ). I
I have a simple list I am using for a horizontal menu: <ul> <h1>Menu</h1>
I have created a horizontal menu with 5 tab options using a ul and

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.