我正在使用来自https://github.com/Dreddik/AndroidTouchGallery的代码来处理 imageView 中的捏合和缩放。现在我添加了隐藏ActionBar
触摸的功能。
问题:dimBar()
每次触摸(单次)时都会调用。因此,当我双击或平移时,顶部栏会不断上下移动
想法:我不知道把这个方法放在代码中的什么地方。我对android真的很陌生,而且我正在使用人们的代码,所以我现在真的很笨。
这是dimBar()
里面TouchImageActivity
public void dimBar () {
if (actionBar.isShowing()) { // hide actionBar
actionBar.hide();
window.getDecorView().setSystemUiVisibility(View.SYSTEM_UI_FLAG_LOW_PROFILE);
}
else {
actionBar.show();
window.getDecorView().setSystemUiVisibility(View.SYSTEM_UI_FLAG_VISIBLE);
}
}
这是 onTouchListener 的部分。
protected void init() {
mTimerHandler = new TimeHandler(this);
matrix.setTranslate(1f, 1f);
m = new float[9];
setImageMatrix(matrix);
setScaleType(ScaleType.MATRIX);
if (Build.VERSION.SDK_INT >= 8)
{
mScaleDetector = new ScaleGestureDetector(mContext, new ScaleListener());
}
setOnTouchListener(new OnTouchListener() {
@Override
public boolean onTouch(View v, MotionEvent rawEvent) {
WrapMotionEvent event = WrapMotionEvent.wrap(rawEvent);
if (mScaleDetector != null)
{
((ScaleGestureDetector)mScaleDetector).onTouchEvent(rawEvent);
}
fillMatrixXY();
PointF curr = new PointF(event.getX(), event.getY());
switch (event.getAction() & MotionEvent.ACTION_MASK) {
case MotionEvent.ACTION_DOWN:
allowInert = false;
savedMatrix.set(matrix);
last.set(event.getX(), event.getY());
start.set(last);
mode = DRAG;
dimBar2();
break;
case MotionEvent.ACTION_POINTER_DOWN:
oldDist = spacing(event);
//Log.d(TAG, "oldDist=" + oldDist);
if (oldDist > 10f) {
savedMatrix.set(matrix);
midPoint(mid, event);
mode = ZOOM;
//Log.d(TAG, "mode=ZOOM");
}
break;
case MotionEvent.ACTION_UP:
allowInert = true;
mode = NONE;
int xDiff = (int) Math.abs(event.getX() - start.x);
int yDiff = (int) Math.abs(event.getY() - start.y);
if (xDiff < CLICK && yDiff < CLICK) {
//Perform scale on double click
long pressTime = System.currentTimeMillis();
if (pressTime - lastPressTime <= DOUBLE_PRESS_INTERVAL) {
if (mClickTimer != null) mClickTimer.cancel();
if (saveScale == 1)
{
final float targetScale = maxScale / saveScale;
matrix.postScale(targetScale, targetScale, start.x, start.y);
saveScale = maxScale;
}
else
{
matrix.postScale(minScale / saveScale, minScale / saveScale, width / 2, height / 2);
saveScale = minScale;
}
calcPadding();
checkAndSetTranslate(0, 0);
lastPressTime = 0;
}
else {
lastPressTime = pressTime;
mClickTimer = new Timer();
mClickTimer.schedule(new Task(), 300);
}
if (saveScale == minScale) {
scaleMatrixToBounds();
}
}
break;
case MotionEvent.ACTION_POINTER_UP:
mode = NONE;
velocity = 0;
savedMatrix.set(matrix);
oldDist = spacing(event);
//Log.d(TAG, "mode=NONE");
break;
case MotionEvent.ACTION_MOVE:
allowInert = false;
if (mode == DRAG) {
float deltaX = curr.x - last.x;
float deltaY = curr.y - last.y;