Android的 - 的意见滚动视图中添加n个 [英] android - add n number of views in scroll view

查看:317
本文介绍了Android的 - 的意见滚动视图中添加n个的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我设计的Andr​​oid平板电脑的应用程序。我创建了包含应用程序栏布局文件,接下来就是一些按钮。在屏幕的中间,我想里面有我需要显示一些图像水平滚动视图。

i am designing an app for android tablets. I have created a layout file which contains the application bar, next is some buttons. In the middle of the screen i want to have a horizontal scroll view inside which i need to show some images.

滚动视图内的图像的数目取决于从URL返回数据。对于这个我保持一个数组列表。根据该数组的大小,我需要创建图像视图withing滚动视图。

The number of images inside the scroll view depends upon the return data from the url. For this i am maintaining an array list. According to the size of the array i need to create the image views withing the scroll view.

我已经把所有的其他按钮,textviews在布局文件,我需要做出上述表示单就通过编码,如何做到这一点。

如果数组的大小是19,然后以下列顺序显示图像的滚动视图中的列表只

If the array size is 19, then the list of images within scroll view to be shown in the following order only

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

在iPad上的iBook应用程式库页面,本本会以这种方式上市的。

In iPad iBook apps library page, the books will be listed out in this way.

如何做到这一点....

how to do this....

推荐答案

感谢 Dheeresh辛格

以下是我的main.xml文件

Following is my main.xml file

<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>

我在我的横向滚动视图我的的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;
                }
            }
        }      
    }
}

在上面的code,我有LR是垂直秩序和查看孩子来显示它的LinearLayout是我必须同时在纵向和横向以显示数据。

in the above code i have lr is the LinearLayout to display it in vertical order and View child is the data which i need to show in both vertical and horizontal order.

非常感谢 Dheeresh辛格

这篇关于Android的 - 的意见滚动视图中添加n个的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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