Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/194.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Android 在ImageView上调用setImageMatrix后是否调用过onSizeChanged()或onDraw()?_Android_Android Imageview - Fatal编程技术网

Android 在ImageView上调用setImageMatrix后是否调用过onSizeChanged()或onDraw()?

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

我正在ImageView上使用调用
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的边界。。。