0

So I'm making a gallery like app and it needs some ScrollView and CardView inside it.

This is the screenshot when I put some background in the ImageView

This is how it suppose to look, I have removed the background image here

I have tried to put an ImageView to inside the CardView with a Linear Layout but the Image filled the ScrollView Instead.

fun CreateCardView(ItemCount: Int){                                                         
   for (i in 1 until ItemCount){                                                           

       val card_view = CardView(this)                                                      
       val param = GridLayout.LayoutParams()                                               
       param.rowSpec = GridLayout.spec(GridLayout.UNDEFINED, 1f)                           
       param.columnSpec = GridLayout.spec(GridLayout.UNDEFINED, 1f)                        
       card_view.layoutParams = param                                                      
       val param2 = card_view.layoutParams as GridLayout.LayoutParams                                                                            
       card_view.layoutParams = param2                                                     
       subLayoutGrid?.addView(card_view)                                                                      

       val linearLayout = LinearLayout(this)                                               
       val layoutParams = WindowManager.LayoutParams(                                      
           WindowManager.LayoutParams.WRAP_CONTENT, // CardView width                      
           WindowManager.LayoutParams.WRAP_CONTENT // CardView height                      
       )                                                                                                                                       
       linearLayout.layoutParams = layoutParams                                                                               
       linearLayout.setBackgroundColor(Color.parseColor("#135517"))                        
       card_view.addView(linearLayout)                                                     


       val imageView = ImageView(this)                                                     
       val imageParams = WindowManager.LayoutParams(                                       
           WindowManager.LayoutParams.MATCH_PARENT,                                        
           WindowManager.LayoutParams.MATCH_PARENT                                         
       )                                                                                   
       imageView.layoutParams = imageParams                                                                                                       
       imageView.setBackgroundResource(R.drawable.animaleight)                             
       val layout = findViewById<LinearLayout>(finallinearId)                              
       layout.addView(imageView)                                                           


   }                                                                                       

}

How can i achieve something like on the image 2 using ImageView

GeraldTDPI
  • 71
  • 11

1 Answers1

0

I beleive it happens because u set width and height of your cardView as WRAP_CONTENT, and images that u put here is very big, so you should either change the size of images or use fixed size of cardView like 100dp height and 100dp-width, but that is not the best option or you can try to change your xml file, if you will put your xml file I will help you with that. Also as long as it is LinearLayout try just put to every item "weight" parametr "1"