簡體   English   中英

將圖像列表添加到滾動視圖

[英]Adding list of images into a scroll view

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

我想將此線性布局添加到正在創建的滾動條中,但看不到任何實現此目的的方法。 還是我走錯路了,有沒有更簡單的方法來完成我想做的事情?

您可以在LinearLayout內部獲取一個ListView,即在水平滾動視圖內部,如下所示:

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

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

</LinearLayout>
</HorizontalScrollView>

同樣,將layout_weight放在ListView中也很重要。 希望對你有效。 另外,您可以查看此自定義的水平滾動ListView教程。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM