Android 在ImageView上调用setImageMatrix后是否调用过onSizeChanged()或onDraw()?
我正在ImageView上使用调用Android 在ImageView上调用setImageMatrix后是否调用过onSizeChanged()或onDraw()?,android,android-imageview,Android,Android Imageview,我正在ImageView上使用调用view.setImageMatrix(matrix)的。问题是,我还想为此ImageView调用onSizeChanged,并且在图像缩放或缩小后,似乎永远不会调用此函数。设置setImageMatrix后是否调用过onDraw()和onSizeChanged()?我希望能够访问此方法: class MyImageView extends ImageView { @Override protected void onSizeChanged(int xNew
view.setImageMatrix(matrix)
的。问题是,我还想为此ImageView
调用onSizeChanged
,并且在图像缩放或缩小后,似乎永远不会调用此函数。设置setImageMatrix后是否调用过onDraw()和onSizeChanged()?我希望能够访问此方法:
class MyImageView extends ImageView {
@Override
protected void onSizeChanged(int xNew, int yNew, int xOld, int yOld)
{
super.onSizeChanged(xNew, yNew, xOld, yOld);
parent = (View) this.getParent();
ViewGroup.LayoutParams params = (ViewGroup.LayoutParams) parent.getLayoutParams();
params.height = yNew;
params.width = xNew;
parent.setLayoutParams(params);
if (parent.getParent() != null) {
if (parent.getParent() instanceof ScrollView) {
((ScrollView) parent.getParent()).smoothScrollBy(xNew,yNew);
((ScrollView) parent.getParent()).setSmoothScrollingEnabled(true);
((ScrollView) parent.getParent()).fullScroll(View.FOCUS_DOWN);
}
}
}
}
在您的情况下,不会调用onSizeChanged()
,因为更改ImageView
的矩阵不会更改视图的大小
但是您可以通过调用setMatrix(matrix)
中的语句来解决问题,如下所示:
@Override
protected void setMatrix(Matrix matrix)
{
super.setMatrix(Matrix matrix);
parent = (View) this.getParent();
ViewGroup.LayoutParams params = (ViewGroup.LayoutParams) parent.getLayoutParams();
params.height = yNew;
params.width = xNew;
parent.setLayoutParams(params);
if (parent.getParent() != null) {
if (parent.getParent() instanceof ScrollView) {
((ScrollView) parent.getParent()).smoothScrollBy(xNew,yNew);
((ScrollView) parent.getParent()).setSmoothScrollingEnabled(true);
((ScrollView) parent.getParent()).fullScroll(View.FOCUS_DOWN);
}
或者,您可以使用ImageView
对象调用所有这些,而无需扩展类。无需连接到onSizeChanged(…)
我的理解是,图像矩阵会影响视图中图像的绘制,而当视图本身的大小更改时,会调用onSizeChanged()。我不认为图像矩阵与onSizeChanged()有任何关系。有没有办法检测实际图像大小何时发生了变化?我正在查看您的代码。。。您是否正在尝试获取一个滚动视图,以显示指示图像中缩放视口位置的滚动条?@krislarson我实际上要做的是使视图随着图像大小的增加而滚动。在使用缩放操作的onTouch()中,可能不是更改图像矩阵,您可以在ImageView上强制布局,并在某个地方的onLayout()方法中更改ImageView的边界。。。