开发者

how can i draw just one item in the gridview

everyone:

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
            }
        }); 

i want开发者_StackOverflow中文版 v to be drawn only,but the fact is every item below v's height got redrawn ,what shall i do .


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 -->
/>
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜