0

我正在为安卓平板电脑设计一个应用程序。我创建了一个包含应用程序栏的布局文件,接下来是一些按钮。在屏幕中间我想要一个水平滚动视图,我需要在其中显示一些图像。

滚动视图中的图像数量取决于 url 的返回数据。为此,我正在维护一个数组列表。根据数组的大小,我需要使用滚动视图创建图像视图。

I have placed all other buttons, textviews in the layout file and i need to make the above said view alone through coding, 这该怎么做。

如果数组大小为 19,则滚动视图中的图像列表仅按以下顺序显示

1  4  7  10  13  16  19
2  5  8  11  14  17    
3  6  9  12  15  18      

在 iPad iBook 应用程序库页面中,书籍将以这种方式列出。

这该怎么做....

4

2 回答 2

1

不确定,但可以尝试这样的方法

1- Create/inflate a horizontal scrollview ..
2- make for loop running i= 0 to x 
        where x= (totalCount/3)+(totalCount%3>0?1:0)
3- Create a  Linear layout with orientation vertical  
4- create one more loop form j=0 to 3 or (i+1)*3+j< totalCount
5- add your element layout in  Linear layout 
6 after the inner loop closed add Linear layout in horizontal scroll-view
  • 循环终止条件,如 x 的值可能不准确,请检查它们

用于使项目可点击

1- take any view from  element layout like in you case image-view is good option  
 2- creates a class in you activity or better to extend you activity with clickListner.
 3- while creating the imageView for each element set this listener to all
 4- Set the data object or index  with element with image-view in tad using SetTag
 5- in Onclick function you will get image-view as argument and use getTag to get that data of attached with clicked element   
于 2012-06-15T06:51:36.373 回答
0

感谢Dheeresh Singh

以下是我的 main.xml 文件

<HorizontalScrollView xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:orientation="vertical" >

        <LinearLayout
            android:id="@+id/linear_1"
            android:layout_width="wrap_content"
            android:layout_height="match_parent"
            android:orientation="horizontal" >
        </LinearLayout>
</HorizontalScrollView>

Horizontal scroll view我的main.xml文件中有我的

public class LayoutActivity extends Activity 
//implements OnClickListener
{
    ViewGroup layout;
    LinearLayout lr;

    int x;
    int total = 4;
    int count = 0;
    LinearLayout lay;

    @Override
    public void onCreate(Bundle savedInstanceState) 
    {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);
        count = 0;
        layout = (ViewGroup)findViewById(R.id.linear_1);
        x = (total/3)+(total%3 > 0?1:0);;
        for(int i = 0; i < x; i++)
        {
            lr = new LinearLayout(this);
            lr.setOrientation(LinearLayout.VERTICAL);
            layout.addView(lr);
            for(int j = 0; j < 3; j++ )
            {
                count++;
                final View child = getLayoutInflater().inflate(R.layout.inflateview, null);
                lay = (LinearLayout)child.findViewById(R.id.threeByThree_tableRow1_1_Layout1);
                lay.setOnClickListener(new View.OnClickListener() 
                {   
                    @Override
                    public void onClick(View v) 
                    {
                        Toast.makeText(getApplicationContext(), "selected  id  is "+child.getId(), Toast.LENGTH_SHORT).show();
                    }
                });
                lr.addView(child);
                child.setId(count);
                if(i == total)
                {
                    break;
                }
            }
        }      
    }
}

在上面的代码中,我有 lr 是 LinearLayout 以垂直顺序显示它,View child 是我需要以垂直和水平顺序显示的数据。

非常感谢Dheeresh Singh

于 2012-06-15T11:02:27.233 回答