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.
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:
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);
}
}
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With