0
我想創建一個帶有架子的GridView。我爲此創建了一個類:Android:帶有滾動架的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時,貨架不能移動。我想我必須在這個類中覆蓋一些方法來移動位圖背景,同時進行滾動。任何建議?
謝謝你,我會嘗試使用選項2. – Rincha 2013-04-11 11:12:49
@Rincha選項2將產生所需的結果,只有當你有足夠的項目來填充整個列表的區域(我寬鬆地認爲一個網格是行列表) 。如果在底部有空行,它會看起來相當有趣:) – 2013-04-11 11:14:24
@Rincha找到答案...? – 2015-10-12 11:35:50