1

我想在 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;
 }

我想将此线性布局添加到我正在创建的滚动条中,但我看不到任何方法可以做到这一点。或者我是不是走错了路,有没有更简单的方法来完成我想做的事情?

4

1 回答 1

1

您可以在 LinearLayout 中使用 ListView,即在水平滚动视图中,如下所示:

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

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

</LinearLayout>
</HorizontalScrollView>

此外,将 layout_weight 放在 ListView 中也很重要。希望对你有效。此外,您可以查看此自定义的水平滚动列表视图教程。

于 2013-09-04T20:59:08.790 回答