Implementation of the gridview bookshelf in Android

Source: Internet
Author: User

In fact, the bookshelf works well. You only need to calculate the location rectangle of the bookshelf in the ondraw () method of the custom gridview, and then the draw will be OK. I personally think it is relatively simple.

The Code is as follows:

Public class playbackfocusedgridview extends focusedgridview {
Drawable minterlayer = This. getresources (). getdrawable (R. drawable. TV _playback_shelf); // bookshelf Image
Rect mmydrawrect = new rect (); // rectangular position of the bookshelf

Public playbackfocusedgridview (context contxt, attributeset attrs, int defstyle ){
Super (contxt, attrs, defstyle );
}

Public playbackfocusedgridview (context contxt, attributeset attrs ){
Super (contxt, attrs );
}

Public playbackfocusedgridview (context contxt ){
Super (contxt );
}

@ Override
Protected void ondraw (canvas ){
Int COUNT = getchildcount ();
If (count> 0) {// when there is content
View v = getchildat (0); // obtain the first visible view on the screen

If (V! = NULL ){
Int gridview_height = This. getheight ();
Int interlayerheight = minterlayer. getintrinsicheight ();
Int blockgapheight = V. getheight ();
Mmydrawrect. Left = 0;
Mmydrawrect. Right = getwidth ();
Int initpos = V. gettop ();

For (INT I = initpos; I <= gridview_height; I ++ = blockgapheight ){
Mmydrawrect. Top = I;
Mmydrawrect. Bottom = mmydrawrect. Top + interlayerheight;
Minterlayer. setbounds (mmydrawrect );
Minterlayer. Draw (canvas); // draw a gallery Image
}
}

Super. ondraw (canvas); // draw each item
}
}
}

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.