gpt4 book ai didi

android - onTouch 同时向上滑动和向下滑动

转载 作者:行者123 更新时间:2023-11-29 01:01:21 28 4
gpt4 key购买 nike

我正在尝试用我的观点做 3 件事。第一次“点击”我的屏幕时,我想将 View 顶部的 ImageView 完全设置为 0alpha 以显示下方 View 。当屏幕水龙头被抬起时,我希望 alpha 回到 1alpha 隐藏图像。接下来,当手指向下并显示图像时,我喜欢在屏幕上上下滑动以更改顶层的 alpha,以便通过它显示下面的图像。我的问题是我无法同时解析 swipeUp、swipeDown 和 touch,它要么只是 swipeUp 和 swipeDown,要么只是触摸!有人可以帮我解决这个问题吗?

        blackPart.setOnTouchListener(new OnSwipeTouchListener(this) {

@Override
public void onSwipeDown() {
Log.d("OK", "bye");
if(drawAlpha > 0.25)
{
drawAlpha -= 0.25;

};
blackPart.setAlpha(drawAlpha);
Log.d("notes", "alpha:" + drawAlpha);

}
@Override
public void onSwipeUp() {
if(drawAlpha < 1.0)
{
drawAlpha += 0.25;
}
blackPart.setAlpha(drawAlpha);

}


@Override
public boolean onTouch(View arg0, MotionEvent arg1)
{

Log.d("notes", "touched");
if(SP.getBoolean("drawingAlwaysVisible", false)) return true;

if(arg1.getAction() == MotionEvent.ACTION_UP) {
Log.d("OK", "action up");
arg0.setAlpha(1.0f);
}
else if(arg1.getAction() == MotionEvent.ACTION_DOWN)
{
arg0.setAlpha(0.0f);
Log.d("OK", "no");
}

return true;
}


});

最佳答案

这是部分代码,应该可以工作

imageView.setOnTouchListener(new View.OnTouchListener() {
@Override
public boolean onTouch(View v, MotionEvent event) {

float eventX = event.getX();
float eventY = event.getY();

switch (event.getAction()) {

case MotionEvent.ACTION_DOWN:

return true;

case MotionEvent.ACTION_MOVE:

int historySize = event.getHistorySize();
for (int i = 0; i < historySize; i++) {
float historicalX = event.getHistoricalX(i);
float historicalY = event.getHistoricalY(i);

if (historicalY >= eventY) {
//move is down
} else {
//move is up
}
if (historicalX >= eventX) {
//move is right
} else {
//move is left
}
eventX = historicalX;
eventY = historicalY;

Log.d(TAG, "onTouch: X = " + eventX);
Log.d(TAG, "onTouch: Y = " + eventY);
}

return true;
}
return false;
}
});

关于android - onTouch 同时向上滑动和向下滑动,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50904779/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com