如何创建视图一样在Android的架子? [英] How to create a shelf like view in Android?

查看:165
本文介绍了如何创建视图一样在Android的架子?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何创建视图一样在Android的架子,显示一些书在任何行?此外,它应该有横向和纵向的功能,如月亮+读卡器的应用程序了。

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.

我可以写水平移动一个货架视图,但它不能完全工作。我用的,包括图片,文字和按钮上的项目XML文件。我写了创建自定义的的ListView ,我称之为货架视图类,扩展适配器视图 。不幸的是,我的计划显示出一排,我不能用它几行。

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.

推荐答案

最近更新:现在,我可以检测为创建货架视图比previous解决方案,更好的一个新途径。我在<一个描述它href="http://www.$c$cproject.com/Articles/389071/Create-a-dynamic-shelfview-in-Android">$c$cProject

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:

  • Horizo​​ntalListView类,它扩展了适配器视图。它从下载 GitHub上

Quaere库的使用几乎相同Linq2Object在.NET。你可以在这里下载

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

04月22日'12:

Apr 22 '12:

有一些方法来实现货架认为,它有两个功能(水平和放大器;垂直滚动)。我试着写一个程序,可以动态地运行。此示例应用程序有一个XML文件和 showShelfView的Java 的类。

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:

主要的XML文件:首先,添加以下code中的的main.xml

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类:内蒙古TableLayout添加多个Horizo​​ntalScroll等于用行数。同时内任何的TableRow添加图片。

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);
        }
    }

}

这篇关于如何创建视图一样在Android的架子?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆