0

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

4

1 に答える 1

2

あなたはこれに正しく近づいていません。この方法で背景を設定しても、スクロール可能にはなりません。背景をスクロールするには、いくつかの方法があります。

  1. リスト アイテムの背景として 1 つの棚を設定する
  2. 横の棚を仕切りの画像に設定し、棚の奥をリストアイテムの画像に設定します。
  3. 横の棚を分割画像として設定し、棚の背面をリストビューの背景として設定します (棚全体の画像で行うように)。

方法 3 が最も近い結果を生成します。これが Apple の iBook の仕組みです。

于 2013-04-11T11:03:40.693 に答える