Horizontal ListView in Android?

后端 未结 19 1208
深忆病人
深忆病人 2020-11-22 03:54

Is it possible to make the ListView horizontally? I have done this using a gallery view, but the selected item comes to the center of the screen automatically.

19条回答
  •  梦如初夏
    2020-11-22 04:37

    For my application, I use a HorizontalScrollView containing LinearLayout inside, which has orientation set to horizontal. In order to add images inside, I create ImageViews inside the activity and add them to my LinearLayout. For example:

    
    
            
    
            
        
    

    An this works perfectly fine for me. In the activity all I have to do is something like the code below:

    LinearLayout imgViewHolder = findViewById(R.id.imageview_holder);
    ImageView img1 = new ImageView(getApplicationContext());
    //set bitmap
    //set img1 layout params
    imgViewHolder.add(img1);
    ImageView img2 = new ImageView(getApplicationContext());
    //set bitmap
    //set img2 layout params
    imgViewHolder.add(img2); 
    

    As I said that works for me, and I hope it helps somebody looking to achieve this as well.

提交回复
热议问题