سؤال

How do i create this kind of views in my application? (The screenshot is actually of an android application available in android market).

enter image description here

I am confused as i assume that we can create the same kind of layout either by using Gridview or by using ListView.

Problems:

  • In Gridview, can we give separator between two rows? can we give background to each row in gridview?
  • In Listview, i think we can customize the listview with 3 books in a row with background, and we can give a separator as well.

From your expert side, please suggest me a possible solution to design and create the same kind of layouts for the android application.

هل كانت مفيدة؟

المحلول

Look at the code of Shelves, written by Romain Guy (one of the ListView's creator).

He used a GridView:

  • no separator

  • background is a bitmap drawable

    < bitmap xmlns:android="http://schemas.android.com/apk/res/android" android:src="@drawable/shelf_panel" android:tileMode="repeat" />

  • background image is like this:

The code is worth a look because it contains other interesting solutions, too.

نصائح أخرى

Stated problems:
In Gridview, can we give separator between two rows? can we give background to each row in gridview?

Well, you can always make up a separator by adding something on the bottom of your view. Make it so that it 'connects' on the sides, and you won't know the difference. It will cost you an extra view per grid-item, so probably not the best option.

In Listview, i think we can customize the listview with 3 books in a row with background, and we can give a separator as well.

Eeuhm, yes, although I don't see what the problem is?

With a ListView, each row is counted as an element, so there will be extra work in logic that keeps each item within the row separate. I would suggest you use a gridview. For each grid element, keep an empty shelf space (for one book) as the background image. This image will include the shelf-base. So there is no need for additional rows. The image should look like this:

Grid Element Background

I would instead suggest to have grid view and view flipper if the number of books are limited.

View flipper will give a better effect than scrolling.

مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top