我正在开发一个 Android 应用程序,它需要在单击按钮时更新 ImageView (和 TextView ),但我希望图像与我的四个 TextView 的高度相匹配。当我设置 imageview 的高度时,它似乎保留了上一次更新的高度,而不是当前的高度。这是我更新图像及其高度的代码。
int nameHeight = t_name.getHeight();
int timeHeight = r_time.getHeight();
int dateHeight = r_date.getHeight();
int locaHeight = r_loca.getHeight();
int totalHeight = nameHeight + timeHeight + dateHeight + locaHeight;
i_img.getLayoutParams().height = totalHeight;
Bitmap image = getBitmapFromURL(event_image.get(eventToUse));
i_img.setImageBitmap(image);
最佳答案
触摸布局参数后,调用 requestLayout()
以使更改生效。
关于java - Android图片设置高度问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21006471/