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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T13:34:21+00:00 2026-05-31T13:34:21+00:00

How do I implement background scrolling with a gridview? If it sounds vague, I

  • 0

How do I implement background scrolling with a gridview? If it sounds vague, I mean like implementing a bookshelf using a gridview where the shelf image is attached to an item in the gridview.

  • 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-31T13:34:21+00:00Added an answer on May 31, 2026 at 1:34 pm

    It took me forever to figure this out, so for everybody trying to do this, here’s the code from my e-book reader.

    It’s based on Shelves by Romain Guy so he deserves the credit for the original code.

    package net.nightwhistler.pageturner.view;
    
    import net.nightwhistler.pageturner.R;
    import net.nightwhistler.pageturner.library.LibraryBook;
    import net.nightwhistler.pageturner.library.QueryResult;
    import android.content.Context;
    import android.graphics.Bitmap;
    import android.graphics.BitmapFactory;
    import android.graphics.Canvas;
    import android.graphics.Rect;
    import android.util.AttributeSet;
    import android.view.KeyEvent;
    import android.widget.GridView;
    
    public class BookCaseView extends GridView {
    
        private Bitmap background;
    
        private int mShelfWidth;
        private int mShelfHeight;   
    
        private QueryResult<LibraryBook> result;    
    
        private LibraryBook selectedBook;   
    
        public BookCaseView(Context context, AttributeSet attributes) {
            super(context, attributes);
    
            this.setFocusableInTouchMode(true);
            this.setClickable(false);
    
            final Bitmap shelfBackground = BitmapFactory.decodeResource(context.getResources(),
                    R.drawable.shelf_single);
            setBackground(shelfBackground);
            this.setFocusable(true);
        }
    
        public void setBackground(Bitmap background) {
            this.background = background;
    
            mShelfWidth = background.getWidth();
            mShelfHeight = background.getHeight();
        }   
    
        protected void onClick( int bookIndex ) {
            LibraryBook book = this.result.getItemAt(bookIndex);
    
            this.selectedBook = book;
            invalidate();
        }
    
        @Override
        protected void dispatchDraw(Canvas canvas) {
            final int count = getChildCount();
            final int top = count > 0 ? getChildAt(0).getTop() : 0;
            final int shelfWidth = mShelfWidth;
            final int shelfHeight = mShelfHeight;
            final int width = getWidth();
            final int height = getHeight();
            final Bitmap background = this.background;
    
            for (int x = 0; x < width; x += shelfWidth) {
                for (int y = top; y < height; y += shelfHeight) {
                    canvas.drawBitmap(background, x, y, null);
                }
    
                //This draws the top pixels of the shelf above the current one
    
                Rect source = new Rect(0, mShelfHeight - top, mShelfWidth, mShelfHeight);
                Rect dest = new Rect(x, 0, x + mShelfWidth, top );              
    
                canvas.drawBitmap(background, source, dest, null);            
            }        
    
    
            super.dispatchDraw(canvas);
        }
    
        @Override
        public boolean onKeyDown(int keyCode, KeyEvent event) {
            if ( keyCode == KeyEvent.KEYCODE_BACK && this.selectedBook != null ) {
                this.selectedBook = null;
                invalidate();
                return true;
            }
    
            return false;
        }   
    
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am trying to implement a fixed background for a website like one over
Background I am trying to implement a RESTful web service using Apache-CXF that interacts
I've been ask to implement a site that is using a very large background
I am trying to implement search on a background thread using NSOperation on iOS
I've been stuck for ages now trying to implement threading or background image loading
How I can implement Background Processing in asp.net. Can anyone give a small and
The background is : I am trying to implement an automated integration test solution.
I want to implement interruptable tasks based on background threads. What is the cleanest
I want to implement a empty div with background color in it. <html> <head>
I implement notifications in my IOS app, and I use customized sounds. Everything works

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.