LinearLayout以编程方式仅显示图像列表对象中的一个图像

问题描述 投票:0回答:1

我正在尝试从Parse Cloud中为特定用户获取图像。下面的代码仅显示一张完整尺寸的图像,而其余的未显示,或者有时列表中的下一幅图像显示出来,但是尺寸非常小。

val query = ParseQuery.getQuery<ParseObject>("image")
        query.whereEqualTo("username", username)
        query.orderByDescending("createdAt")
        query.findInBackground { objects, e ->
            if(e == null && objects.isNotEmpty()) {
                for (row in objects) {
                    val parseFile = row.get("image") as ParseFile

                    parseFile.getDataInBackground { data, exception ->
                        if(exception == null && data != null) {
                            val bitmap = BitmapFactory.decodeByteArray(data, 0, data.size)
                            val imageView = ImageView(applicationContext)
                            with(imageView) {
                                layoutParams = ViewGroup.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT)
                                setImageBitmap(bitmap)
                            }
                            linearLayout.addView(imageView)
                        }else {
                            Toast.makeText(applicationContext, exception.message, Toast.LENGTH_SHORT).show()
                        }
                    }
                }
            }
        }
android kotlin parse-platform
1个回答
1
投票

在ScrollView中放入linearLayout并将其高度设置为wrap_content。

© www.soinside.com 2019 - 2024. All rights reserved.