将图像列表添加到滚动视图中

时间:2013-09-04 20:53:08

标签: android layout scrollview android-image

我想在android中有一个滚动条显示每个单独的植物,以便用户可以按一个选择它,创建一个新的Plant对象,然后他可以在屏幕上移动。

我在填写此列表时遇到了麻烦。

我有HorizontalScrollView

bar = (HorizontalScrollView)findViewById(R.id.horizontalScrollView1);

我的代码首当其冲发生在

private LinearLayout loadBar(ArrayList<Plant> listOfPlants, HorizontalScrollView bar){
     LinearLayout layout = new LinearLayout(getApplicationContext());

     layout.setHorizontalScrollBarEnabled(true);
     ImageView image= new ImageView(getApplicationContext());
     ArrayList<View> images = new ArrayList<View>();
     for (int i = 0; i < list.size(); i++) {

         image = listOfPlants.get(i).getPhoto();
         images.add(image);

    }
    layout.addTouchables(images);
    return layout;
 }

我想将此线性布局添加到我正在创建的滚动条中,但我没有看到任何方法来执行此操作。或者我是以错误的方式解决这个问题,是否有更简单的方法来获得我想做的事情?

1 个答案:

答案 0 :(得分:1)

你可以在LinearLayout中取一个ListView,它位于水平滚动视图中,如下所示:

<HorizontalScrollView ...........>
<LinearLayout ......>
    <LinearLayout ......>
    //List View Titles will be here
    </LinearLayout>

    <ListView ........ android:layout_weight="1" />

</LinearLayout>
</HorizontalScrollView>

此外,将layout_weight放在ListView中也很重要。希望对你有效。另外,您可以查看此customized horizontally scrollable listview教程。