Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
我需要更改图像视图中的图像然后获取宽度。问题是,它给了我最后一张图片的宽度。
headpic.setImageResource(head[x]); int width = headpic.getWidth();
如果我然后再次运行此代码,x 是相同的值,它会得到正确的宽度。
我假设 headpic 是您的图像视图。如果是这样,不会headpic.getWidth();获得图像视图的宽度而不是图像吗?
headpic.getWidth();
您可以从图像视图中获取可绘制对象并使用.getIntrinsicWidth();
.getIntrinsicWidth();