Как я могу нарисовать только один элемент в сетке - PullRequest
0 голосов
/ 14 июля 2011

все

gridView.setOnItemClickListener(new OnItemClickListener() {
            @Override
            public void onItemClick(AdapterView<?> parent, View v, int position, long id) {
//              v.invalidate(0, 0, 5, 5);
                v.invalidate(); //v is a ImageView here
            }
        }); 

Я хочу, чтобы v рисовался только, но дело в том, что каждый элемент ниже высоты v перерисован, что мне делать.

1 Ответ

0 голосов
/ 14 июля 2011
public class MyGridView extends GridView 
{
    private Bitmap background;

    public MyGridView(Context context, AttributeSet attrs) 
    {
        super(context, attrs);
        background = BitmapFactory.decodeResource(getResources(), R.drawable.bg);
    }
}

@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 y = top; y < height; y += backgroundHeight)
    {
        for (int x = 0; x < width; x += backgroundWidth)
        {
            canvas.drawBitmap(background, x, y, null);
        }
    }

    super.dispatchDraw(canvas);
}

xml

<your.package.name.MyGridView 
    android:id="@+id/mygridview"
    <!-- other GridView configuration parameters -->
/>
Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...