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