我需要通过 id 找到一个视图,然后覆盖它的onMeasure
方法。有谁知道这是怎么做到的吗?
以下内容在 Java 中不起作用,但从概念上讲,这是我所需要的:
ImageView myImage = (ImageView) findViewById(R.id.some_pic);
myImage.onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
super.onMeasure(widthMeasureSpec, heightMeasureSpec);
int width = MeasureSpec.getSize(widthMeasureSpec);
int height = MeasureSpec.getSize(heightMeasureSpec);
showOther(width, height);
};
myImage.setImageBitmap(bmp);
Java 提供了这个
ImageView myImage = new ImageView(this) {
@Override
protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
super.onMeasure(widthMeasureSpec, heightMeasureSpec);
int width = MeasureSpec.getSize(widthMeasureSpec);
int height = MeasureSpec.getSize(heightMeasureSpec);
showOther(width, height); }
};
或这个
ImageView myImage. = (ImageView) findViewById(R.id.some_pic);
myImage.setImageBitmap(bmp);
我想过使用setOnMeasureListener
但没有为 ImageView 定义这样的方法。关于如何实现这一点的任何想法?