我在调用view.setImageMatrix(matrix)
的ImageView上使用pinch and zoom function。问题是我还想为此onSizeChanged
调用ImageView
,并且在图像缩放或缩小图像后似乎永远不会调用此函数。是否设置了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);
}
}
}
}
答案 0 :(得分:0)
onSizeChanged()
,因为更改ImageView
的矩阵不会更改View
的大小。
但您可以通过调用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(...)
。