Reputation: 2321
I want to create a GridView with shelves. I have created a class for this:
public class ShelveGridView extends GridView{
private Bitmap background;
public ShelveGridView(Context context, AttributeSet attrs) {
super(context, attrs);
background = BitmapFactory.decodeResource(getResources(), R.drawable.bibliotca_image_shelf);
}
@Override
protected void dispatchDraw(Canvas canvas) {
int count = getChildCount();
int top = count < 0 ? getChildAt(0).getTop() : 0;
int backgroundWidth = background.getWidth();
int backgroundHeight = background.getHeight();
int width = getWidth();
int height = getHeight();
for (int x = 0; x < width; x += backgroundWidth)
for (int y = top; y < height; y += backgroundHeight)
canvas.drawBitmap(background, x, y, null);
super.dispatchDraw(canvas);
}...
but when I scroll the GridView, shelves not move. I guess that I have to overwrite some method in this class to move the Bitmap background while I do scroll. Any suggestion?
Upvotes: 0
Views: 745
Reputation: 57346
You're not approaching this correctly. Setting a background in this way will not make it scrollable. There are several ways to make the background scroll:
Method 3 will produce the closest results and this is how apple's iBooks works.
Upvotes: 2