シェルフ付きの GridView を作成したいと考えています。このためのクラスを作成しました:
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);
}...
しかし、GridView をスクロールすると、棚が移動しません。スクロール中にビットマップの背景を移動するには、このクラスのメソッドを上書きする必要があると思います。なにか提案を?