16

How to create a shelf like view in android that show several book in any row? Also, it should have horizontal and vertical features like the moon+reader app has.

I can write a shelf view that moves horizontally but it doesn't fully work. I used a xml file for view items that included image, text and button. I wrote a class that extends AdapterView to create a customized ListView that I called "shelf view". Unfortunately, my program show one row and I can't use it for several row.

enter image description here

user
  • 86,916
  • 18
  • 197
  • 190
azad
  • 361
  • 2
  • 5
  • 17
  • 1
    Can you show us what did you achieve so far? –  Apr 15 '12 at 10:40
  • Yeah of curse, I used to a xml file for view items that included image,text and buttom. I wrote a class extends AdaptorView for create a customize listview that I called it:"shelf view". Unfortunately, my program show one row and I can't use it for several row. Did you get it? – azad Apr 16 '12 at 04:05

1 Answers1

20

Last Updated: Now, I can detect a new way for create shelf-view better than the previous solution. I described it in CodeProject

By the Way, In this application I used two classes:

  • HorizontalListView Class that extends the AdapterView. It downloaded from GitHub

  • Quaere library use almost same as Linq2Object in .Net. You can download here.


Apr 22 '12:

There are some ways to implement shelf view that it have two features(horizontal & vertical scroll). I try to write a program that can run dynamically. This sample App have a XML file and a showShelfView java class.

So you can see my App:

main XML file: First, Add following code in main.XML

<?xml version="1.0" encoding="utf-8"?>
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:id="@+id/sclView">
    <TableLayout
            android:id="@+id/tblLayout"
            android:layout_width="fill_parent"
            android:layout_height="fill_parent" 
           android:padding="0dp">
    </TableLayout>
</ScrollView>

showShelfView Class: Inner TableLayout add several HorizontalScroll equals with number of rows. Also inner any TableRow add Image.

Don't forget set a shelf image for Row's background:

enter image description here

public class showShelfView extends Activity {

    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);


        int numRow = 4;
        int numCol = 8;

        TableLayout tblLayout = (TableLayout) findViewById(R.id.tblLayout);

        for(int i = 0; i < numRow; i++) {
            HorizontalScrollView HSV = new HorizontalScrollView(this);
            HSV.setLayoutParams(new LayoutParams(LayoutParams.FILL_PARENT, LayoutParams.FILL_PARENT));

            TableRow tblRow = new TableRow(this);
            tblRow.setLayoutParams(new LayoutParams(LayoutParams.FILL_PARENT, LayoutParams.WRAP_CONTENT));
            tblRow.setBackgroundResource(R.drawable.bookshelf);

            for(int j = 0; j < numCol; j++) {
            ImageView imageView = new ImageView(this);
                imageView.setImageResource(R.drawable.book1);

                TextView textView = new TextView(this);
                textView.setText("Java Tester");
                textView.setLayoutParams(new LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT));

                tblRow.addView(imageView,j);
            }

            HSV.addView(tblRow);
            tblLayout.addView(HSV, i);
        }
    }

}
Omid Nazifi
  • 5,235
  • 8
  • 30
  • 56
  • @omidnaz i couldnt able to find the Quaere Library on the specified link and i search it out everywhere but still not fin d....could you please let me know where i can get this library.... – Vivek Singh Sep 15 '12 at 07:33
  • @vivek-singh: You should get it's source with SVN. exact address is "http://quaere.codehaus.org/Get+Involved" – Omid Nazifi Sep 16 '12 at 04:45
  • @omidnazifi i wasted my full day but couldn't resolve how can i get the library on the link you have given....there are lots of links related to quaere....but there is no option to download or save the "Quaere LIbrary"...please do help me out how can i import the quaere library to my project........ – Vivek Singh Sep 16 '12 at 17:17
  • 1
    @vivek-singh: As I mentioned it if you wanna get it, you should use SVN and write this url into SVN software "http://svn.codehaus.org/quaere/trunk/". but you can download my code from code-project, I added Lib into it. – Omid Nazifi Sep 17 '12 at 04:37
  • Making available for all the screens I found it difficult!! Really confusing which one to use tblLayout, tblRow to fill/match parent? – LOG_TAG Mar 30 '13 at 12:01
  • 1
    @Subra I've written a new way and updated my solution. please note first line "**Last Updated**". In new way I used *ListView*. – Omid Nazifi Mar 31 '13 at 03:27