所以我正在制作类似app的图库,并且其中需要一些ScrollView和CardView。
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
我尝试将ImageView放入具有线性布局的CardView内,但是图像填充了ScrollView。
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)
}
}
如何使用ImageView在图像2上实现类似的效果