java - 如何覆盖 boolean PhotoViewAttacher onFling(MotionEvent, MotionEvent, float, float) 的限制?
问题描述
PhotoViewAttacher
' 会boolean onFling(MotionEvent, MotionEvent, float, float)
阻止调用 myOnSingleFlingListener
的onFling
方法,除非当前比例是最小值。
我OnSingleFlingListener
从com.github.chrisbanes.photoview
. 但是,由于该onFling
方法仅对包可见,因此首先调用PhotoViewAttacher
' 的方法。防止我的方法在. 我需要我的,除非。(当我的图像宽度与窗口宽度匹配时。)我该如何解决这个问题?我需要自己制作整个包的副本并修改为公开吗?onFling
PhotoViewAttacher.onFling
onFling
scale > DEFAULT_MIN_SCALE
scale > getMediumScale()
scale == getMediumScale()
PhotoView
OnSingleFlingListener.onFling
我的代码:
public class BasicViewActivity extends AppCompatActivity implements DownloadCallback, OnSingleFlingListener {
@Override
public boolean onFling(MotionEvent e1, MotionEvent e2, float velocityX, float velocityY) {
. . .
return true;
}
OnSingleFlingListener:
package com.github.chrisbanes.photoview;
public interface OnSingleFlingListener {
boolean onFling(MotionEvent e1, MotionEvent e2, float velocityX, float velocityY);
}
PhotoViewAttacher:
@Override
public boolean onFling(MotionEvent e1, MotionEvent e2, float velocityX, float velocityY) {
if (mSingleFlingListener != null) {
if (getScale() > DEFAULT_MIN_SCALE) {
return false;
}
. . .
return mSingleFlingListener.onFling(e1, e2, velocityX, velocityY);
}
return false;
}
我想要我的onFling
被叫时getScale() <= getMediumScale()
。相反,我的onFling
方法仅在getScale() == DEFAULT_MIN_SCALE
.
解决方案
我决定解决它。
- 我克隆了 PhotoView 包。
- 我将它的源代码复制到我自己的包中。
我更改了上面提到的一行(并添加了一个分数以防止浮点错误):
if(getScale() > getMediumScale() + .01f) { return false; }
推荐阅读
- iis-6 - IIS:服务没有及时响应启动或控制请求。(2147943453, 8007041d)
- penetration-testing - 使用 burp 套件的 Web 应用程序
- javascript - cordova ios iphone x - 顶部0的固定元素不显示在最顶部
- python - 如何对在 __init__ 方法之外初始化的实例变量进行单元测试
- r - 基于包含 tidyverse 类别的其他两列创建新变量
- powershell - 如何查询不同域中的 AD 用户
- jpos - 在 jboss 中部署 jPOS 或在 jboss 中启动 jPOS Q2
- react-native - 我想在本机反应中调用 Object-C 方法
- ruby-on-rails - 如何编写 Rspec HTTP 方法来访问嵌套的显示视图?
- python - Django to_html() 更新以允许用户选择行