LinearLayout 以编程方式仅显示图像列表对象中的一个图像
LinearLayout displays only one image out of Image List Object programmatically
我正在尝试从 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()
}
}
}
}
}
将linearLayout放在ScrollView中,并设置其高度为wrap_content。
我正在尝试从 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()
}
}
}
}
}
将linearLayout放在ScrollView中,并设置其高度为wrap_content。