Hello Friends,
Today I am going to show you that how
you can create Book Shelf View in android. I research soo many and
finally i reached to one best and simple way to create shelf View in
Android.
In this example i have implemented the
Custom Shelf View which will create a shelf. The list of the books
will come in the form of JSON response and by parsing it show the
details of books in shelfview along with its thumbnails. I wrote a
class that extends
AdapterView
to create
a customized GridView
that I called
"shelf view"
.
Below is the code of ShelView:
BookShelfView.java
public class BookshelfView extends GridView {
private Bitmap background;
public BookshelfView(Context context) {
super(context);
init();
}
public BookshelfView(Context context, AttributeSet attrs) {
super(context, attrs);
init();
}
public BookshelfView(Context context, AttributeSet attrs, int defStyle) {
super(context, attrs, defStyle);
init();
}
protected void init() {
//Set the background image of the ShelfView panel.
background = BitmapFactory.decodeResource(getResources(), R.drawable.shelf_panel_new);
}
//Draw a background in the screen and create multiple panels using height & width.
@Override
protected void dispatchDraw(Canvas canvas) {
int top = getChildCount() > 0 ? getChildAt(0).getTop() : 0;
for (int y = top; y < getHeight(); y += background.getHeight()) {
for (int x = 0; x < getWidth(); x += background.getWidth()) {
canvas.drawBitmap(background, x, y, null);
}
}
super.dispatchDraw(canvas);
}
}
In the demo please change the Url according to your needs to get the list of books.
For more details Download Source Code
Reference:
- http://www.mybestcv2.co.il/TextPage_EN.aspx?ID=11123278
- https://code.google.com/p/shelves/
- http://www.android86.com/android/shelf-view-example-in-android/
- http://stackoverflow.com/questions/10161225/how-to-create-a-shelf-like-view-in-android
- http://www.codeproject.com/Articles/389071/Create-a-dynamic-shelfview-in-Android
- http://www.android86.com/android/shelf-view-example-in-android/